OpenAPI 3.0:请求中不存在授权标头

时间:2020-06-03 15:34:58

标签: swagger openapi swagger-2.0

我正在从Swagger 2转换为OpenAPI 3。 在Swagger 2中,代码工作正常,但在OpenAPI 3中,它不会在curl请求中生成授权标头。

Swagger 2.0代码会生成正确的请求

 /facilities:
    get:
      tags:
        - "facilities"
      summary: "Get all the facilities"
      description: ""
      operationId: "allfacilities"
      produces:
        - "application/json; version=1"

      parameters:
        - in: "header"
          name: X-USER-EMAIL
          description: ""
          required: true
          type: "string"

        - in: "header"
          name: Authorization
          description: ""
          required: true
          type: "string"

      responses:
        200:
          description: "successful operation"
          schema:
            $ref: "#/definitions/Facilities"

卷曲请求正确生成:

curl -X GET "https://localhost:8080/test_metadata/api/facilities" -H "accept: application/json; version=1" -H "X-USER-EMAIL: joy.smith@xmail.com" -H "Authorization: Bearer r1XUcjNby60NYtPHcWUS7_Nl4EsZnCQaA53qMoHYFhs"

以下是OpenAPI 3的新代码

  /facilities:
    get:
      tags:
      - facilities
      summary: Get all the facilities
      operationId: allfacilities
      parameters:
      - name: X-USER-EMAIL
        in: header
        required: true
        schema:
          type: string
      - name: Authorization
        in: header
        required: true
        schema:
          type: string
      responses:
        200:
          description: successful operation
          content:
            application/json; version=1:
              schema:
                $ref: '#/components/schemas/Facilities'

的前面
- name: Authorization

它显示了一条消息,即“忽略标题为Authorization的标题参数。请使用SecuritySchemes和Security部分来定义授权”

并生成以下卷曲请求

curl -X GET "https://localhost:8080/test_metadata/api/facilities" -H "accept: application/json; version=1" -H "X-USER-EMAIL: joy.smith@xmail.com"  

您能帮我在适当的位置定义“ 授权

0 个答案:

没有答案