설명
OpenAPI 3.0에서 components.headers의 정의를 $ref로 재사용할 수 있습니다. 참조 대상이 없으면 응답 헤더의 형식이나 의미를 문서 도구가 올바르게 표시하지 못할 수 있습니다.
잠재적 영향
- 문서에서 응답 헤더의 정보가 누락될 수 있습니다.
- 참조 해석에 실패해 문서 검증이나 클라이언트 생성에 문제가 생길 수 있습니다.
해결 방법
로컬 헤더 참조의 경로와 컴포넌트 이름을 components.headers의 정의에 맞추세요. 이름의 대소문자도 정확히 일치해야 합니다. 외부 문서를 참조한다면 대상 파일과 경로를 확인하고, 수정 후 참조가 해석되는지 검증하세요.
예시
응답의 headers에서 X-Pages 헤더 정의를 참조하는 예시입니다. 첫 예제의 wPages는 정의되어 있지 않습니다.
변경 전
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/wPages"
}
}
}
}
}
}
},
"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"
}
}
}
}
}
변경 후에는 실제 정의된 xPages를 참조해 헤더의 정수 형식을 설명합니다. 컴포넌트 이름의 일치 여부는 HTTP 헤더 이름의 대소문자 처리와 별개입니다.