説明
操作と最上位のどちらにも security がなければ、その操作には仕様上の認証要件がありません。公開する操作では有効な設定です。
想定される影響
保護する操作でも、生成したクライアントが認証情報を省略し、リクエストが拒否される場合があります。
対処方法
保護する操作からサーバーの認証方式を参照してください。複数の操作が同じ要件を使う場合は最上位の security にまとめます。
例
どちらの例にも exampleSecurity の定義があります。全体の要件にこの名前を追加すると、GET / でも X-API-Key を送ることが伝わります。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"exampleSecurity": []
}
],
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}