설명
components.headers는 재사용할 헤더를 정의하는 곳입니다. 공통 헤더를 쓰는 각 응답에서 이 정의를 참조해야 합니다.
잠재적 영향
사용자가 어떤 응답에 이 헤더가 포함되는지 알기 어렵고, 쓰이지 않는 정의도 관리 대상으로 남습니다.
해결 방법
응답의 headers에서 $ref로 공통 정의를 참조하고, 헤더 이름과 스키마를 실제 응답에 맞추세요. 정의를 삭제하기 전에 다른 문서의 참조도 확인하세요.
예시
첫 번째 예시는 xPages를 정의합니다. 변경 후에는 200 응답이 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"
}
}
}
}
}