go-swagger3 icon indicating copy to clipboard operation
go-swagger3 copied to clipboard

How to add oneOf to the schema

Open yeshwanthPentakota opened this issue 1 year ago • 2 comments
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'

yeshwanthPentakota avatar Jun 02 '24 18:06 yeshwanthPentakota

any updates?

ghost avatar Mar 13 '25 14:03 ghost

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{}

qequ avatar Apr 09 '25 15:04 qequ