Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation Extensions for Documenting Multiple Response Formats #1760

Open
kaptinlin opened this issue Feb 13, 2024 · 1 comment
Open

Annotation Extensions for Documenting Multiple Response Formats #1760

kaptinlin opened this issue Feb 13, 2024 · 1 comment

Comments

@kaptinlin
Copy link

Is your feature request related to a problem? Please describe.

Yes, the problem arises when trying to document API endpoints that are capable of returning multiple response formats based on the request's Accept header or specific query parameters. Currently, swag does not offer a straightforward way to annotate a single API endpoint to document these multiple potential response formats. This limitation leads to less accurate and comprehensive API documentation. For instance, I find it frustrating when I have an endpoint that can return data in either JSON or CSV format, but I'm unable to document both response types accurately using swag annotations. This forces me to choose a single response format for documentation or resort to external documentation methods to convey the full capabilities of the endpoint.

Describe the solution you'd like

I would like swag to support enhanced annotation capabilities that allow documenting multiple response formats for a single API endpoint. Specifically, the solution should include:

  1. Multiple @Success and @Failure Annotations: Allow these annotations to be specified multiple times for the same HTTP status code but with different Produce fields to document the different MIME types an endpoint can produce.

  2. Introduction of a Produce Field in Response Annotations: This field would specify the MIME type of the response. It would be used alongside the current fields in @Success and @Failure annotations to link the documented response format directly with its MIME type.

Example Annotation with Proposed Changes:

// @Success 200 {object} YourJsonResponseModel "Successfully retrieved the article in JSON format." Produce(application/json)
// @Success 200 {string} string "Successfully retrieved the article in CSV format." Produce(text/csv)

This enhancement would allow developers to accurately document the full range of an API endpoint's capabilities directly within their code, improving the clarity and utility of the generated API documentation.

Additional context

The ability to return different response formats from a single API endpoint is a common requirement for modern web services, catering to various client needs and preferences. Enhancing swag to support documenting these capabilities directly in code annotations would significantly improve the tool's utility and the quality of the generated documentation. This feature would make swag a more comprehensive tool for documenting complex APIs, ultimately benefiting developers and API consumers alike by providing clearer, more accurate, and more accessible API documentation.

@sdghchj
Copy link
Member

sdghchj commented Feb 20, 2024

It seems your proposal is at presentation level.

Refer to operationObject , one status code with one schema.

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

No branches or pull requests

2 participants