기본값과 타입 불일치 (OpenAPI 3.0)

default 값이 선언된 데이터 타입과 맞지 않는 경우

설명

스키마의 default 값은 해당 필드의 타입과 일치해야 합니다. 예를 들어 type: integer에 문자열 "a"를 기본값으로 지정하면 타입 규칙과 기본값이 충돌합니다.

잠재적 영향

코드 생성이나 검증이 실패하거나, 기본값을 사용하는 클라이언트에서 타입 오류가 발생할 수 있습니다.

해결 방법

default를 실제 타입과 허용 범위에 맞게 수정하세요. 값이 생략됐을 때 서버가 적용하는 동작도 문서의 기본값과 일치하는지 확인하세요.

예시

다음 OpenAPI 3.0 예시는 정수 스키마의 기본값을 문자열 "a"에서 정수 1로 수정합니다.

변경 전

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": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": "a",
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

변경 후

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": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": 1,
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

참조