我在定义OpenAPI(Swagger)文档的自定义请求头时遇到了问题。我已经查看了文档https://swagger.io/docs/specification/describing-parameters/#header-parameters,但我无法让它起作用。
以下是我的示例,其中包含一个具有请求体的POST请求。我还希望它具有像第二个代码片段中的自定义头,但那样不合法。
这是可以的:
/search:
post:
tags:
- Domain
summary: Search for domains
description: Returns a domain if it was found.
produces:
- application/json
parameters:
- in: body
name: body
description: Array of Domain Names
required: true
schema:
$ref: '#/definitions/DomainNames'
这是不行的:
/search:
post:
tags:
- Domain
summary: Search for domains
description: Returns a domain if it was found.
produces:
- application/json
parameters:
- in: header
name: X-Request-ID
schema:
type: string
format: uuid
required: true
- in: body
name: body
description: Array of Domain Names
required: true
schema:
$ref: '#/definitions/DomainNames'
在-in: header
行中,我遇到了以下错误:
paths['/search'].post.parameters[0].in的架构错误
应该等于允许的值之一
allowedValues:body、header、formData、query、path
跳转到第37行paths['/search'].post.parameters[0]的架构错误
不应该有附加属性
additionalProperty:schema、in、name
跳转到第37行
我错过了什么?这个头部显示在呈现的Swagger UI中,但我无法“保存”它,因为它无效。