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

[Feature Request] Add Support for Defining Examples for Non-Struct Response Types #1965

Open
AminBhr opened this issue Jan 20, 2025 · 0 comments

Comments

@AminBhr
Copy link

AminBhr commented Jan 20, 2025

Is your feature request related to a problem? Please describe.
When defining a success response that uses a non-struct type, such as a string, it is currently not possible to define an example for it. As a result, when viewing the Swagger UI, the response example section simply displays "string." This lack of customization reduces the clarity and usability of the API documentation. I would like a way to define examples for non-struct types in Swagger.

Image

Describe the solution you'd like
Similar to how examples are defined for parameters (#1119 ), it would be great to have a similar format for responses. For example:
// @Success 201 {string} string "User created successfully" example("User created successfully")
With this implementation, the Swagger UI would display:

Image

Additional context
The example content should be added to the response schema as per the OpenAPI v2 specification (reference here):

                "responses": {
                    "201": {
                        "description": "User created successfully",
                        "schema": {
                            "type": "string",
                            "example": "user created successfully"
                        },
                        "headers": {
                            "Location": {
                                "type": "string",
                                "description": "/users/{id}"
                            }
                        }
                    },
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

1 participant