OpenAPI 3.0 컴포넌트 이름 형식 오류

컴포넌트 이름에는 영문자, 숫자, 점, 하이픈과 밑줄을 사용하세요.

설명

OpenAPI 3.0의 components에서 스키마·응답·파라미터 이름에는 영문자와 숫자, 점(.), 하이픈(-), 밑줄(_)만 사용하세요. 빈 이름과 공백은 허용되지 않습니다.

잠재적 영향

도구가 이름을 처리하지 못하면 참조 해석이나 코드 생성이 실패할 수 있습니다.

해결 방법

이름을 바꾸면 다른 문서에서 참조하는 경우도 포함해 해당 $ref를 모두 수정하세요. 문서를 검증하고 각 참조가 새 이름으로 해석되는지 확인하세요.

예시

예시의 스키마 이름 General Error에는 공백이 있습니다.

변경 전

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": "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": {
      "General Error": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "code": {
            "type": "string",
            "format": "int32"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    }
  }
}

변경 후

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": "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",
            "format": "int32"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    }
  }
}

이 이름을 GeneralError로 바꿉니다. 예시 안에는 이 스키마를 가리키는 $ref가 없습니다.

참조