説明
全体の security で参照する名前は components.securitySchemes のスキーム名と一致させてください。
想定される影響
名前が一致しないと、クライアント生成ツールが API のデフォルトの認証方式を特定できない場合があります。
対処方法
参照先の名前で実際の認証方式を定義します。OAuth2 と OpenID Connect には必要なスコープを指定し、ほかの方式には [] を使います。同じ要件をサーバーでも適用してください。
例
例の全体設定が参照するのは petstore_auth です。プロバイダーの HTTPS エンドポイントを指定し、クライアントと認可サーバーで PKCE を設定してください。 ペット用のスコープ名は例です。実際の操作に必要なスコープだけを要求してください。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"components": {
"securitySchemes": {
"regularSecurity": {
"type": "http",
"scheme": "basic"
},
"petstore_auth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
},
"authorizationUrl": "https://example.org/api/oauth/dialog",
"tokenUrl": "https://example.org/api/oauth/token"
}
}
}
}
}
}
別途定義した regularSecurity はこの要件では使いません。