파라미터 allowEmptyValue 적용 범위 점검

allowEmptyValue의 적용 범위와 실제 빈 값 처리 정책을 확인하세요.

설명

OpenAPI 3.0은 allowEmptyValue 사용을 권장하지 않습니다. 빈 값을 표현할 수 있는 직렬화 방식을 쓰는 쿼리 매개변수에만 적용됩니다.

잠재적 영향

클라이언트가 보낸 빈 값을 서버가 거부할 수 있습니다.

해결 방법

경로, 헤더, 쿠키 매개변수에서는 이 옵션을 제거하세요. 쿼리 매개변수는 값을 생략한 요청과 빈 값을 명시한 요청을 각각 보내 서버 동작을 확인하세요.

예시

예시의 id는 경로에 필요한 정수입니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/{id}": {
      "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "description": "ID of the API version",
          "required": true,
          "allowEmptyValue": true,
          "schema": {
            "type": "integer"
          }
        }
      ]
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/{id}": {
      "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "in": "path",
          "style": "label",
          "description": "ID of the API version",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "name": "id"
        }
      ]
    }
  }
}

style: label은 경로의 표기 방식을 바꿉니다. 정수 값은 여전히 필요합니다.

참조