-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
API response wrapper usage #497
Comments
No, this structure is common for every response. |
Unfortunately it's not possible to define a response this way.
The most simple way is to define a response for each endpoint
|
My Common Response like yours
My response struct like this:
My Solution is: Define a struct base CommonResponse and DictResponse in another package "api"
then change the route comment
|
Reference #651. |
Describe the bug
In our project, we use a API response wrapper struct as shown below for all responses. The response contains "meta" which has status code and error message if any and a "data" section which can include another struct. I am not sure how to make swag include other structs.
Here the actual response is APIResponse{ Meta: Meta{200,ErrorMessage:""}, Data : Cars{"ABC","DEF"}
with the annotation // @success 200 {object} APIResponse, swag generates definitions for "Meta" struct and leave "Data" as an object type without reference. This is as expected.
Is there anyway to specify that "Data" should refer "Cars" struct ? something like below?
Your swag version
1.4.1
Your go version
1.12.1
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: