Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we set global "consumes" and "produces" in Swagger?

In the each path I need to set consumes and produces. Can I set them globally?

post:
      summary: ""
      description: ""
      consumes:
      - "application/json"
      - "application/xml"
      produces:
      - "application/xml"
      - "application/json"
like image 706
Toxa Avatar asked Dec 18 '22 05:12

Toxa


1 Answers

Sure. You can specify consumes and produces on the root level of the spec, and they will be inherited by all operations. Global consumes and produces can be overridden on the operation level if needed.

consumes:
  - application/json
  - application/xml
produces:
  - application/xml
  - application/json

paths:
  /foo:
    get:
      # This inherits global `produces`
      ...

    post:
      # Here we override global `consumes`
      consumes:
        - application/x-www-form-urlencoded
      ...

More info: https://swagger.io/docs/specification/2-0/mime-types/

like image 86
Helen Avatar answered Dec 31 '22 10:12

Helen