swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.79k stars 1.21k forks source link

oneOf multiple responses with the same http code #1617

Open denisgubin opened 1 year ago

denisgubin commented 1 year ago

Is your feature request related to a problem? Please describe.

// @Success 200 {object} someStruct1
// @Success 200 {object} someStruct2

Describe the solution you'd like https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

for example in gererated openapi.yaml file I would like to see something like that:

    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                oneOf:
                - "$ref": "#/definitions/someStruct1"
                - "$ref": "#/definitions/someStruct2"

Is it possible to use 'oneOf' in swaggo v1.8.12 ?

I've found article about swagger 2.0 and openapi 3.0 https://stackoverflow.com/a/44534699 But is there alternative way to get multiple responses with the same http-code in swaggo?

I guess only one thing that can I do is merge fields someStruct1 and someStruct2 into one someStruct3 struct.

    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                - "$ref": "#/definitions/someStruct3"

https://stackoverflow.com/a/47453822

Thanks for your answers!

SladeThe commented 1 year ago

Up! I also would be glad to somehow generate oneOf responses.