설명
요청 본문을 로컬 $ref로 참조할 때는 #/components/requestBodies/ 뒤에 정의한 이름을 쓰세요. 외부 파일의 요청 본문 객체도 참조할 수 있습니다.
잠재적 영향
참조가 끊기면 API 사용자가 본문의 미디어 유형이나 필드를 알기 어렵고, 검증이나 클라이언트 생성이 실패할 수 있습니다.
해결 방법
요청 본문의 content에서 미디어 유형과 스키마 참조를 확인하세요. 명세를 검증하고 서버가 실제로 받는 형식과 비교하세요.
예시
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
},
"requestBody": {
"$ref": "#/components/requestBodies/MyWrongObjectBody"
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"requestBodies": {
"MyObjectBody": {
"description": "A JSON object containing my object information",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
},
"requestBody": {
"$ref": "#/components/requestBodies/MyObjectBody"
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"requestBodies": {
"MyObjectBody": {
"description": "A JSON object containing my object information",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
POST /는 정의되지 않은 MyWrongObjectBody를 MyObjectBody로 고칩니다. JSON 요청 본문은 MyObject 스키마를 사용합니다. 200 응답도 자체 content에서 같은 스키마를 참조합니다.