존재하지 않는 OpenAPI 3.0 예제 참조

예제 참조와 실제 정의를 일치시켜 요청과 응답 데이터를 정확히 설명하세요.

설명

OpenAPI 3.0의 예제는 요청과 응답 데이터를 이해하는 데 도움을 줍니다. 로컬 $ref가 components.examples에 없는 이름을 가리키면 도구가 예제 데이터를 표시하거나 재사용할 수 없습니다.

잠재적 영향

  • 요청이나 응답 예제가 문서에서 누락되거나 잘못 표시될 수 있습니다.
  • 참조 오류로 검증이나 문서 생성이 실패할 수 있습니다.
  • API 사용자가 데이터 구조를 이해하는 데 시간이 더 걸릴 수 있습니다.

해결 방법

예제 $ref가 실제 components.examples 항목을 가리키는지 확인하세요. 이름 변경, 삭제와 오타를 정리하고 외부 참조의 URI와 대상도 검증하세요. 예제가 실제 스키마와 미디어 타입에 맞는지 확인하세요.

예시

첫 문서는 objectExample을 정의하지만 존재하지 않는 wrongExample을 참조합니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyObject"
                },
                "examples": {
                  "objectExample": {
                    "$ref": "#/components/examples/wrongExample"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyObject"
                },
                "examples": {
                  "objectExample": {
                    "$ref": "#/components/examples/objectExample"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "examples": {
      "objectExample": {
        "value": {
          "id": "1",
          "name": "new object"
        },
        "summary": "A sample object"
      }
    }
  }
}

변경 후에는 실제 정의된 objectExample을 참조합니다. 참조를 수정해도 서버의 응답 데이터가 자동으로 바뀌지는 않으므로 실제 응답과 예제를 함께 관리하세요.

참조