Skip to content

feat(goctl): support custom Swagger response status - #5691

Merged
kevwan merged 2 commits into
zeromicro:masterfrom
kevwan:feat/swagger-http-status-code-5667
Jul 19, 2026
Merged

feat(goctl): support custom Swagger response status#5691
kevwan merged 2 commits into
zeromicro:masterfrom
kevwan:feat/swagger-http-status-code-5667

Conversation

@kevwan

@kevwan kevwan commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #5667

Adds @doc(respCode: "201") for a typed custom response and @doc(responses: "200-OK
401-Unauthorized") for documented alternatives. Invalid status codes preserve the existing HTTP 200 default. Includes regression coverage and updated Swagger examples.

Fixes zeromicro#5667

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kevwan
kevwan marked this pull request as ready for review July 19, 2026 03:09
Copilot AI review requested due to automatic review settings July 19, 2026 03:09
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the goctl api swagger generator to allow .api authors to document non-200 HTTP response status codes in generated Swagger/OpenAPI output, addressing the feature request in #5667 while keeping backward-compatible defaults.

Changes:

  • Add @doc(respCode: "...") support to set the primary response status code (fallback remains 200 for invalid values).
  • Add @doc(responses: "...") support to document additional response codes/descriptions (e.g., common error responses) alongside the primary schema-bearing response.
  • Add regression tests and update Swagger example fixtures to demonstrate respCode.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/goctl/api/swagger/response.go Implements parsing of respCode / responses and emits multiple Swagger responses with appropriate schema/description placement.
tools/goctl/api/swagger/const.go Adds new @doc property keys: respCode and responses.
tools/goctl/api/swagger/response_test.go Adds coverage for defaulting, quoted values, invalid codes, no-body responses, and multiple response descriptions.
tools/goctl/api/swagger/example/example.api Demonstrates @doc(respCode: "201") usage in the example API.
tools/goctl/api/swagger/example/example.swagger.json Updates generated example output to show a 201 response key.
tools/goctl/api/swagger/example/example_cn.api Chinese example updated to demonstrate @doc(respCode: "201").
tools/goctl/api/swagger/example/example_cn.swagger.json Updates Chinese generated example output to show a 201 response key.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kevwan
kevwan merged commit 565bcb3 into zeromicro:master Jul 19, 2026
6 checks passed
@kevwan
kevwan deleted the feat/swagger-http-status-code-5667 branch July 19, 2026 15:57
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.

Feature Request: Support custom HTTP Status Code in Swagger generate from .api file.

2 participants