Can we set global “consumes” and “produces” in Swagger?

牧云@^-^@ 提交于 2020-01-14 14:04:06

问题


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"

回答1:


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/



来源:https://stackoverflow.com/questions/45484702/can-we-set-global-consumes-and-produces-in-swagger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!