Skip to content

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
sync/hanyu.liang/feature-zcf-v0.1
Open

fix(rest): fix Go SDK generator for Delete-via-POST and Get-with-inventories#3435
zstack-robot-2 wants to merge 1 commit intofeature-zcf-v0.1from
sync/hanyu.liang/feature-zcf-v0.1

Conversation

@zstack-robot-2
Copy link
Collaborator

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}inventory key → SDK 报 key not found

修复: 新增 generateDeleteViaPostMethod,使用 PostWithRespKey + 空 responseKey + Event View 返回类型。

影响范围: APIDeleteSSOClientMsg, APIDeleteSSORedirectTemplateMsg, APIDeleteCdpTaskDataMsg

Bug 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

File Change
rest/src/main/resources/scripts/GoApiTemplate.groovy Fix dispatch for Delete-via-POST; fix non-unwrap Get to use response wrapper type

Test plan

  • 重新生成 Go SDK,验证 DeleteSSOClient 生成 PostWithRespKey + DeleteSSOClientEventView
  • 重新生成 Go SDK,验证 GetSSOClient 生成 GetSSOClientView 返回类型
  • 验证其他 Delete-via-POST API(DeleteSSORedirectTemplate, DeleteCdpTaskData)生成正确
  • 验证不影响正常 POST/GET/PUT/DELETE 方法生成

sync from gitlab !9292

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 21e815b3-b2be-454d-8554-b4eba167664d

📥 Commits

Reviewing files that changed from the base of the PR and between 4435a59 and c3d81cf.

📒 Files selected for processing (1)
  • rest/src/main/resources/scripts/GoApiTemplate.groovy

Walkthrough

为 GoApiTemplate.groovy 添加了通过 POST 实现删除的生成器方法、在非解包场景下引入运行时视图结构解析,并在 POST 分支中基于 HTTP 注解优先判定 actionType 以调整生成方法分派与模板引用。

Changes

Cohort / File(s) Summary
模板主逻辑与分支调整
rest/src/main/resources/scripts/GoApiTemplate.groovy
在非查询/普通 POST 处理分支中增加 actionType == "Delete" 路径,确保 HTTP 方法注解优先于类名推断的 actionType;调整引用以在非解包时使用 runtime 确定的 actualViewStruct。
Delete-via-POST 生成器与注释
rest/src/main/resources/scripts/GoApiTemplate.groovy
新增私有方法 generateDeleteViaPostMethod(String apiPath, String responseStructName),生成通过 POST 执行 Delete 的客户端方法(处理路径占位符、可选额外参数,并以空 responseKey 使用 PostWithRespKey 来解析无 inventory key 的响应);添加详细注释说明占位符和响应解析行为。

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: 返回解析结果
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 新方法跳又忙,
POST 删路藏锋芒,
视图悄换运行时,
模板生成步步祥,
胡萝卜在窗旁 🥕


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error 标题格式正确遵循 [scope]: ,共76字符(超过72字符限制),但内容准确反映两个主要修复(Delete-via-POST 和 Get-with-inventories)。 缩短标题至72字符或以内,例如:'fix(rest): fix Go SDK for Delete-via-POST and Get-inventories' 或 'fix(rest): fix Delete-via-POST and Get-inventories in Go SDK'。
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed 描述详细说明了两个 Bug、修复方案和影响范围,完全相关于变更集内容,提供了清晰的背景和测试计划。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/hanyu.liang/feature-zcf-v0.1

Comment @coderabbitai help to get the list of available commands and usage tips.

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
@MatheMatrix MatheMatrix force-pushed the sync/hanyu.liang/feature-zcf-v0.1 branch from 4435a59 to c3d81cf Compare March 9, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants