5

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"
Helen
  • 87,344
  • 17
  • 243
  • 314
Toxa
  • 63
  • 1
  • 7

1 Answers1

13

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.

swagger: '2.0'
...

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/

Helen
  • 87,344
  • 17
  • 243
  • 314