잘못된 스키마 객체 참조 (OpenAPI 3.0)

데이터 구조를 설명하는 스키마 참조가 잘못된 경우

설명

스키마의 $ref는 유효한 스키마 객체를 가리켜야 합니다. 경로나 대상이 잘못되면 요청이나 응답 데이터의 필드와 타입을 해석할 수 없습니다.

잠재적 영향

검증이나 모델 생성이 실패하거나 문서의 데이터 구조 정보가 누락될 수 있습니다.

해결 방법

공통 모델은 #/components/schemas/...의 실제 스키마를 참조하세요. 유효한 외부 스키마도 사용할 수 있으며, 이름과 객체 종류를 함께 확인하세요.

예시

다음 발췌 예시는 GeneralError의 참조 경로에서 schemads를 schemas로 수정합니다. tshirt 예시 정의와 요청 본문을 사용하는 작업은 생략했습니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.c"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    },
    "requestBodies": {
      "NewItem": {
        "description": "Multipart item data",
        "required": true,
        "content": {
          "multipart/form-data": {
            "schema": {
              "$ref": "#/components/schemads/GeneralError"
            },
            "examples": {
              "tshirt": {
                "$ref": "#/components/examples/tshirt"
              }
            }
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.c"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    },
    "requestBodies": {
      "NewItem": {
        "description": "Multipart item data",
        "required": true,
        "content": {
          "multipart/form-data": {
            "schema": {
              "$ref": "#/components/schemas/GeneralError"
            },
            "examples": {
              "tshirt": {
                "$ref": "#/components/examples/tshirt"
              }
            }
          }
        }
      }
    }
  }
}

참조