説明
最上位の security: [] は、API 共通の認証要件を設定しない指定です。個々の操作には要件を指定できます。
想定される影響
このデフォルトを使うと、保護された操作でもクライアントが認証情報を送らない場合があります。
対処方法
共通の認証が必要なら、全体の security から定義済みスキームを参照します。例外は公開する操作に限り、サーバーでも同じポリシーを適用してください。
例
security: [{exampleSecurity: []}] は exampleSecurity の API キーを要求します。内側の [] はスコープの一覧で、API キーでは空にします。
変更前
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"exampleSecurity": []
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}