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

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

설명

OpenAPI 3.0에서 default는 같은 스키마의 type과 일치해야 합니다.

잠재적 영향

타입이 다르면 검증이나 SDK 생성이 실패하거나 기본값을 사용하는 클라이언트에서 오류가 날 수 있습니다.

해결 방법

실제 허용 범위 안에서 기본값을 고르세요. 값이 생략됐을 때 서버와 클라이언트가 문서대로 처리하는지 확인하세요.

예시

예시는 GET /의 200 응답 기본값을 문자열 "a"에서 정수 1로 바꿉니다. 1은 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": "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
                }
              }
            }
          }
        }
      }
    }
  }
}

참조