未定義の認証方式を参照するOpenAPI 2.0ドキュメント

securityの認証方式名はsecurityDefinitionsの定義と一致させる必要があります。

説明

Swagger 2.0 の security に記述するスキーム名は、securityDefinitions に定義した名前と一致させてください。

想定される影響

参照先がないと検証に失敗したり、生成したクライアントが送るべき認証情報を判別できなかったりします。

対処方法

サーバーが要求するスキームを定義するか、誤った参照を修正します。OAuth2 では認可サーバーのフロー、URL、スコープと照合し、文書を検証して操作の権限を確認してください。

例

最初の例は api_key だけを定義して petstore_auth を要求しています。2 つ目は petstore_auth を accessCode フローで定義します。実際の認可・トークン URL を指定し、GET / に write:pets と read:pets の両方が必要か確認してください。

変更前

json
{
  "swagger": "2.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "security": [
    {
      "petstore_auth": [
        "write:pets",
        "read:pets"
      ]
    }
  ],
  "securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "name": "api_key",
      "in": "header"
    }
  },
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  }
}

変更後

json
{
  "swagger": "2.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "security": [
    {
      "petstore_auth": [
        "write:pets",
        "read:pets"
      ]
    }
  ],
  "securityDefinitions": {
    "petstore_auth": {
      "type": "oauth2",
      "flow": "accessCode",
      "authorizationUrl": "https://example.com/oauth/authorize",
      "tokenUrl": "https://example.com/oauth/token",
      "scopes": {
        "write:pets": "modify pets in your account",
        "read:pets": "read your pets"
      }
    }
  },
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  }
}

参考資料