사용하지 않는 요청 본문 컴포넌트 (OpenAPI 3.0)

공통 요청 본문 정의가 API 작업과 연결되지 않은 경우

설명

components.requestBodies에는 재사용할 요청 본문을 정의합니다. 작업에서 받는 본문은 해당 작업의 requestBody에 표시합니다.

잠재적 영향

사용자가 어떤 데이터를 보내야 할지 알기 어렵고, 입력 형식이 바뀔 때 쓰이지 않는 정의까지 검토하게 될 수 있습니다.

해결 방법

본문을 받는 작업에서 공통 정의를 참조하고, 콘텐츠 유형과 스키마를 실제 요청에 맞추세요. 정의를 삭제하기 전에 다른 문서에서도 사용하는지 확인하세요.

예시

첫 번째 예시는 MyObjectBody를 정의합니다. 변경 후에는 POST 작업의 requestBody에서 이를 참조해 JSON 입력 형식을 설명합니다.

변경 전

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"
                }
              }
            }
          }
        }
      }
    }
  },
  "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"
            }
          }
        }
      }
    }
  }
}

참조