설명
OpenAPI 2.0의 security에서 사용하는 인증 이름은 securityDefinitions에 정의되어 있어야 합니다. 정의되지 않은 이름을 참조하면 어떤 인증 방식과 자격 증명을 요구하는지 명세에서 확인할 수 없습니다.
잠재적 영향
유효하지 않은 참조로 명세 검증이나 클라이언트 생성이 실패하거나, 개발자가 인증 요구사항을 잘못 이해할 수 있습니다.
해결 방법
참조 이름을 실제 정의와 일치시키고 OAuth2를 사용하는 경우 필요한 범위도 정의하세요. 인증 요구사항을 단순히 삭제하지 말고 서버의 실제 정책과 일치하도록 수정하세요.
예시
변경 전에는 petstore_auth의 정의가 없습니다. 변경 후에는 해당 이름과 범위를 정의합니다. 예시의 OAuth2 URL은 실제 인증 제공자의 주소로 바꾸세요.
변경 전
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"
}
}