feat(goctl): support custom Swagger response status - #5691
Merged
kevwan merged 2 commits intoJul 19, 2026
Conversation
Fixes zeromicro#5667 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
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 remains200for 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>
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.
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.