설명
requestBody의 $ref는 요청 본문 객체를 가리켜야 합니다. 스키마만으로는 미디어 타입과 본문 구조를 함께 설명하는 요청 본문 객체를 대신할 수 없습니다.
잠재적 영향
요청 본문의 형식이 문서에 누락되거나 클라이언트가 잘못된 요청을 만들 수 있습니다.
해결 방법
공통 요청 본문은 #/components/requestBodies/...에서 참조하고 스키마는 그 객체의 content 안에 두세요. 외부 파일의 유효한 요청 본문 객체도 참조할 수 있습니다.
예시
다음 POST 예시는 List의 참조 경로를 schemas에서 requestBodies로 수정합니다.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"components": {
"requestBodies": {
"List": {
"description": "id of api version",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
}
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"requestBody": {
"$ref": "#/components/schemas/List"
},
"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"
}
]
}
]
}
}
}
}
}
}
}
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"components": {
"requestBodies": {
"List": {
"description": "id of api version",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
}
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"requestBody": {
"$ref": "#/components/requestBodies/List"
},
"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"
}
]
}
]
}
}
}
}
}
}
}
}
}
}
}