allowEmptyValue is used in an unsupported location

Use allowEmptyValue only at parameter locations supported by the OpenAPI version.

Description

OpenAPI 2.0 permits allowEmptyValue on query and formData parameters. OpenAPI 3.0 limits it to query and discourages its use. required controls whether the parameter must be present.

Potential impact

Clients may send empty values at locations where tools ignore or reject the setting.

Remediation

Check the version and parameter location. For a path parameter, remove allowEmptyValue and keep the route. For a query parameter, test omission and an empty value separately.

Examples

These OpenAPI 3.0 excerpts omit info and the operation’s responses.

Before

json
{
  "openapi": "3.0.0",
  "paths": {
    "/users/{id}": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "allowEmptyValue": true,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "paths": {
    "/users": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "allowEmptyValue": true,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    }
  }
}

Changing /users/{id} to /users moves id into the query. Omitting required also makes it optional. Use this version only if clients may call the new route without an ID.

References