설명
components.headers는 재사용할 헤더 정의를 보관합니다. 여기에 정의하는 것만으로 응답에 헤더가 추가되지는 않으며, 필요한 위치에서 참조해야 합니다.
잠재적 영향
사용자가 실제 응답에 없는 헤더를 기대하거나 불필요한 헤더 정의를 유지보수할 수 있습니다.
해결 방법
응답의 headers 등 실제 사용 위치에서 $ref로 연결하고 이름과 스키마를 실제 헤더에 맞추세요. 외부 사용도 확인한 뒤 불필요한 정의를 제거하세요.
예시
다음 예시는 응답의 headers에서 X-Pages를 공통 정의인 xPages에 연결합니다.
변경 전
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": "success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}
변경 후
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": "success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
},
"headers": {
"X-Pages": {
"$ref": "#/components/headers/xPages"
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}