OAS3:为什么在Response中定义了Accept标头?

时间:2018-11-27 16:04:05

标签: swagger swagger-2.0 swagger-codegen oas

它说here不应将OAS3 Yaml文件内的Accept标头定义为参数,而应定义为responses.<code>.content.<media-type>。例:

paths:
  /employees:
    get:
      summary: Returns a list of employees.
      responses:
        '200':      # Response
          description: OK
          content:  # Response body
            application/json:  # Media type
              schema:          # Must-have
                type: object   # Data type
                properties: 
                  id:
                    type: integer
                  name:
                    type: string
                  fullTime: 
                    type: boolean
                example:       # Sample data
                    id: 1
                    name: Jessica Right
                    fullTime: true

这让我感到奇怪,因为如果我使用swagger-codegen基于该OAS3文件创建客户端,则在以下情况下,“ content:”(在我的示例为application/json)下面提到的字符串将按原样用作Accept标头使用该客户端进行/employees调用。因此,下面的代码段(标识使用我的API的个人)(“ userID”)将没有任何效果:

DefaultApi api = new DefaultApi();
api.getApiClient().addDefaultHeader("Accept", "application/vnd.mycompany.userID.v1+json");

但是作为我的API的所有者,我不想为每个用户提供摇摇欲坠的文件。

为什么在响应部分中定义OAS3中的Accept标头,我认为该标头仅应定义结果的媒体类型?

0 个答案:

没有答案
相关问题