You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to annotate an existing API in JSend style. The following struct represents the structure of every API response:
package server
typeGeneralResponsestruct {
Statusstring`json:"status"`Datainterface{} `json:"data"`Messagestring`json:"message,omitempty"`// only used when status = "error"
}
Handlers return this struct with a specific stuct in the Data interface, e.g., the getStatus handler retruns a GeneralResponse with a StatusResp as Data:
package server
typeStatusRespstruct {
StatusCodeintStatusMessagestring
}
How can I annotate my code in such a way, that the model of my response is a GeneralResponse containing a StatusResp?
Swaggo/swag let you overwrite the interface with a specific type. Is there a way to do something similar for go-swagger?
There are some related Issues: #619, #1708
In #619 (comment), @casualjim suggests to have a look at the allOf and discriminated functions, but as far as I understood those, they are not solving this problem, since I don't want multiple possible values of Data, but one specific.
Problem statement
I am trying to annotate an existing API in JSend style. The following struct represents the structure of every API response:
Handlers return this struct with a specific stuct in the Data interface, e.g., the getStatus handler retruns a GeneralResponse with a StatusResp as Data:
How can I annotate my code in such a way, that the model of my response is a GeneralResponse containing a StatusResp?
Swaggo/swag let you overwrite the interface with a specific type. Is there a way to do something similar for go-swagger?
There are some related Issues: #619, #1708
In #619 (comment), @casualjim suggests to have a look at the
allOf
anddiscriminated
functions, but as far as I understood those, they are not solving this problem, since I don't want multiple possible values of Data, but one specific.This is my current state:
This is close to what I want, but has the following problems:
It would be nice to do it like this:
Environment
swagger version: v0.27.0
go version: 1.14
OS: Ubuntu 18.04 LTS
The text was updated successfully, but these errors were encountered: