如何在OpenAPI 2.0中同时使用主体和标头参数定义操作?

问题描述 投票:2回答:1

OpenAPI 2.0(Swagger 2.0)定义如何在同一操作中具有主体和标头参数?我尝试了以下方法:

  /image-correction:
    post:
      operationId: image-correction_create
      tags:
        - image-corrections
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: requestBody
          description: imageCorrection
          schema:
            $ref: '#/definitions/ImageCorrection'
        - in: header
          name: X-Request-ID
          schema:
            type: string
            format: uuid
          required: true

但是Swagger编辑器显示错误:

不应具有附加属性AdditionalProperty:模式

swagger swagger-2.0 openapi swagger-editor
1个回答
1
投票

在OpenAPI 2.0中,标头,查询和路径参数不使用schema,它们直接使用type。更改标题参数,如下所示:

    - in: header
      name: X-Request-ID
      type: string     # <----
      format: uuid     # <----
      required: true

在所有参数类型都使用openapi: 3.0.0的OpenAPI 3.0(schema)中对此进行了更改。

© www.soinside.com 2019 - 2024. All rights reserved.