잘못된 응답 객체 참조 (OpenAPI 3.0)

응답 위치에서 스키마 등 다른 종류의 객체를 참조하는 경우

설명

상태 코드의 $ref는 응답 객체를 가리켜야 합니다. 이 객체는 설명을 제공하며 헤더와 본문 형식도 지정할 수 있습니다.

잠재적 영향

스키마를 직접 참조하면 검증이 실패하거나 생성된 문서에 해당 응답이 잘못 표시될 수 있습니다.

해결 방법

#/components/responses/... 또는 외부 파일의 응답 객체를 참조하세요. 본문 스키마가 있으면 응답의 content 안에서 해당 미디어 유형의 schema에 지정하세요.

예시

GET /의 200 응답은 #/components/responses/Success를 참조해 응답 설명과 JSON 예시를 가져옵니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "components": {
    "responses": {
      "Success": {
        "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"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "$ref": "#/components/schemas/Success"
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "components": {
    "responses": {
      "Success": {
        "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"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          }
        }
      }
    }
  }
}

참조