我们可以设定全球"消费"和"生产"在Swagger?

时间:2017-08-03 12:49:42

标签: swagger swagger-2.0

在每个路径中,我需要设置consumesproduces。我可以在全球范围内设置它们吗?

post:
      summary: ""
      description: ""
      consumes:
      - "application/json"
      - "application/xml"
      produces:
      - "application/xml"
      - "application/json"

1 个答案:

答案 0 :(得分:7)

不确定。您可以在规范的根级别指定consumesproduces,并且它们将由所有操作继承。如果需要,可以在操作级别覆盖全局consumesproduces

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
      ...

更多信息:https://swagger.io/docs/specification/2-0/mime-types/