존재하지 않는 OpenAPI 3.0 응답 참조

응답 참조를 실제 응답 정의와 연결하세요.

설명

상태 코드에서 로컬 공통 응답을 참조할 때는 $ref의 이름을 components.responses의 정의와 일치시키세요. 외부 파일의 응답 객체도 참조할 수 있습니다.

잠재적 영향

대상을 찾지 못하면 클라이언트 생성이 실패하거나 API 사용자가 해당 상태 코드의 응답을 처리하는 데 필요한 정보를 얻지 못할 수 있습니다.

해결 방법

참조를 바로잡고 명세를 검증하세요. 상태 코드, 설명, 헤더와 본문 구조가 서버의 실제 응답과 일치하는지 확인하세요.

예시

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "404": {
            "$ref": "#/components/responses/NotRight"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ]
      }
    },
    "responses": {
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ]
      }
    },
    "responses": {
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}

GET /의 404 응답은 정의되지 않은 NotRight 대신 NotFound를 참조합니다. JSON 본문의 Error 스키마는 code와 message를 필수 문자열로 지정합니다.

참조