説明
操作の security は配列で指定します。security: {} は無効です。OpenAPI 3.0 では、security: [{}] で匿名アクセスを許可できます。
想定される影響
型が誤っていると仕様の検証に失敗します。意図せず匿名アクセスを許可すると、保護された操作でもクライアントが認証情報を省略することがあります。
対処方法
保護する操作では、配列に認証方式と必要なスコープを指定します。全体の要件が適切なら操作の security を省略して継承してください。認証が不要な操作には security: [] を指定してください。
例
例では GET / に OAuth2 の read スコープを指定しています。OAuth2 の URL はプロバイダーのエンドポイントに置き換えてください。
変更前
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": {},
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"OAuth2": [
"read"
]
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "Read API versions"
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": [
{
"OAuth2": [
"read"
]
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"OAuth2": [
"read"
]
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "Read API versions"
}
}
}
}
}
}
}