fix(rest): fix Go SDK generator for Delete-via-POST and Get-with-inventories#3435
Open
zstack-robot-2 wants to merge 1 commit intofeature-zcf-v0.1from
Open
fix(rest): fix Go SDK generator for Delete-via-POST and Get-with-inventories#3435zstack-robot-2 wants to merge 1 commit intofeature-zcf-v0.1from
zstack-robot-2 wants to merge 1 commit intofeature-zcf-v0.1from
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough为 GoApiTemplate.groovy 添加了通过 POST 实现删除的生成器方法、在非解包场景下引入运行时视图结构解析,并在 POST 分支中基于 HTTP 注解优先判定 actionType 以调整生成方法分派与模板引用。 Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant GeneratedMethod as GeneratedClientMethod
participant HTTP as HTTPServer
participant Parser as ResponseParser
Client->>GeneratedMethod: 调用 deleteViaPost(apiPath, params)
GeneratedMethod->>HTTP: POST /items/{id}/delete (body params)
HTTP-->>GeneratedMethod: HTTP 200 + body (可能无 inventory key)
GeneratedMethod->>Parser: Parse response with empty responseKey
Parser-->>GeneratedMethod: 返回 parsed responseStruct
GeneratedMethod-->>Client: 返回解析结果
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
1. Delete-via-POST: detect actionType=="Delete" with httpMethod==POST and generate PostWithRespKey with empty responseKey instead of Post with hardcoded "inventory" key. Handles URL placeholders via buildFullPath. 2. Get-with-inventories: when reply has "inventories" (List) instead of "inventory" (single), use the response struct directly with GetWithRespKey and empty responseKey to unmarshal the full response. Resolves: ZCF-0 Change-Id: I708245d6bd49172fd27488a506dec57d2bfd73ee
4435a59 to
c3d81cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复
GoApiTemplate.groovy中两个 Go SDK 生成逻辑问题:Bug 1: Delete-via-POST 生成错误代码
当
actionType == "Delete"但@RestRequest(method = HttpMethod.POST)时(如APIDeleteSSOClientMsg),生成器走generateCreateMethod→ 生成cli.Post(),内部用"inventory"key 反序列化。但 Delete Event 返回{"success":true}无inventorykey → SDK 报key not found。修复: 新增
generateDeleteViaPostMethod,使用PostWithRespKey+ 空 responseKey + Event View 返回类型。影响范围:
APIDeleteSSOClientMsg,APIDeleteSSORedirectTemplateMsg,APIDeleteCdpTaskDataMsgBug 2: Get-with-inventories 返回空数据
当 Get API 的 Reply 有
inventories(List) 而非inventory(单个) 字段时(如APIGetSSOClientReply),inventoryFieldName为 null →unwrapForGet = false→ 走!unwrap分支,用viewStructName(元素类型如SSOClientInventoryView)接收{"inventories":[...]}→ 字段不匹配 → 数据全空。修复: 在
!unwrap分支中,当viewStructName != responseStructName时使用responseStructName(包装类型如GetSSOClientView)。Changes
rest/src/main/resources/scripts/GoApiTemplate.groovyTest plan
DeleteSSOClient生成PostWithRespKey+DeleteSSOClientEventViewGetSSOClient生成GetSSOClientView返回类型DeleteSSORedirectTemplate,DeleteCdpTaskData)生成正确sync from gitlab !9292