我有一个 openapi 3.0.0 的 swagger 文档。我的 API 有多个标记为 required: true 的标头,但包含下划线并标记为 required: true 的标头被绕过。
yaml 的部分片段 -
info:
version: 0.0.1
servers:
- url: http://localhost:3000/myapi
paths:
/place/{id}:
get:
x-eov-operation-id: find place
x-eov-operation-handler: Ctrl
parameters:
- name: unique_id
in: header
required: true
schema:
type: string
description: unique id
- name: app-code
in: header
required: true
schema:
type: string
description: unique id
responses: <<continued with response definition>>
“app-code”的标头验证按预期工作,但“unique_id”验证被绕过。一旦我将“unique_id”更改为“unique-id”,它就可以正常工作..
我们知道 openapi 3.0 文档是否禁止使用下划线吗?
根据 OAS 3.0.x 规范,您使用
_
是有效的。
"parameters": {
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9\\.\\-_]+$": {
"oneOf": [
{
"$ref": "#/definitions/Reference"
},
{
"$ref": "#/definitions/Parameter"
}
]
}
}
src:https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.0/schema.json#L223C9-L236C12
这可能是您使用的软件包有错误。您没有明确说明标头验证在哪里被“绕过”。