전역 인증 요구사항이 없는 OpenAPI 문서

공통 인증 정책이 있다면 전역 security에 명시하고 개별 작업의 예외를 확인하세요.

설명

최상위 security는 API의 기본 인증 요구사항입니다. 이 필드를 생략하면 인증이 필요한 작업마다 요구사항을 지정해야 합니다.

잠재적 영향

작업에도 요구사항이 없으면 클라이언트는 해당 요청에 인증 정보가 필요하다는 사실을 알 수 없습니다.

해결 방법

공통 요구사항은 최상위 security에, 예외는 각 작업에 지정하세요. 참조할 방식은 OpenAPI 3.0의 components.securitySchemes 또는 2.0의 securityDefinitions에 정의하고 서버에서도 같은 정책을 적용하세요.

예시

예시의 GET /는 전역 petstore_auth 요구사항을 상속합니다. OAuth2 URL은 공급자의 엔드포인트로 바꾸세요. read:pets와 write:pets는 예시 스코프입니다. 실제 작업에 필요한 것만 요구하세요.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "security": [
    {
      "petstore_auth": [
        "write:pets",
        "read:pets"
      ]
    }
  ],
  "components": {
    "securitySchemes": {
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "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"
            }
          }
        }
      }
    }
  }
}

참조