설명
전역 security에서 참조하는 이름은 components.securitySchemes의 이름과 일치해야 합니다.
잠재적 영향
이름이 일치하지 않으면 클라이언트 생성 도구가 API의 기본 인증 방식을 찾지 못할 수 있습니다.
해결 방법
실제 인증 방식을 같은 이름으로 정의하세요. OAuth2와 OpenID Connect에는 필요한 스코프를 지정하고 다른 방식에는 []를 사용하세요. 서버에서도 해당 요구사항을 적용하세요.
예시
예시의 전역 요구사항은 petstore_auth를 참조합니다. OAuth2 엔드포인트를 공급자의 HTTPS 주소로 바꾸고 클라이언트와 인증 서버에서 PKCE를 설정하세요. read:pets와 write:pets는 예시 스코프입니다. 실제 작업에 필요한 것만 요구하세요.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"components": {
"securitySchemes": {
"regularSecurity": {
"type": "http",
"scheme": "basic"
},
"petstore_auth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
},
"authorizationUrl": "https://example.org/api/oauth/dialog",
"tokenUrl": "https://example.org/api/oauth/token"
}
}
}
}
}
}
별도로 정의한 regularSecurity는 이 요구사항에 적용되지 않습니다.