설명
Swagger 2.0의 security에 적은 이름은 securityDefinitions에 정의한 스킴 이름과 정확히 일치해야 합니다.
잠재적 영향
이름이 일치하지 않으면 검증이 실패하거나 생성된 클라이언트가 어떤 자격 증명을 보낼지 알 수 없습니다.
해결 방법
서버가 요구하는 스킴을 정의하거나 잘못된 참조를 고치세요. OAuth2라면 인가 서버의 흐름·URL·스코프를 확인하고, 문서를 검증한 뒤 해당 작업의 권한과 비교하세요.
예시
첫 예시는 api_key만 정의하면서 petstore_auth를 요구합니다. 두 번째는 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"
}
}