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:模式
在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
)中对此进行了更改。