go-swagger3
go-swagger3 copied to clipboard
How to add oneOf to the schema
trafficstars
type Response struct {
field1 *string json:"field1,omitempty"
field2 *string json:"field2,omitempty"
}
I want to indicate that the response will either contain field1 or field2
Sample spec:
Response:
oneOf:
- $ref: '#/components/schemas/Response1'
- $ref: '#/components/schemas/Response2'
any updates?
Hi, I'm seeing this ticket but not understanding the example passed @yeshwanthPentakota
maybe something like this could work
// Response1 is a response containing field1
type Response1 struct {
Field1 string `json:"field1" example:"hello"`
}
// Response2 is a response containing field2
type Response2 struct {
Field2 string `json:"field2" example:"world"`
}
// Response is either a Response1 or a Response2
// @oneOf Response1, Response2
type Response interface{}