Skip to content

[Bug]: Query parameter validation fails to match empty string when listed as a valid enum value #1210

Open

Description

@Youssef1313

Actual Behavior

Run the following code:

from openapi_core import OpenAPI
from openapi_core.testing import MockRequest

SPEC = {
    "openapi": "3.2.0",
    "info": {"title": "Sample", "version": "1.0.0"},
    "paths": {
        "/api": {
            "get": {
                "tags": ["Sample"],
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {"enum": ["Active", "Inactive", "Pending", ""]},
                    }
                ]
            }
        }
    },
    "tags": [{"name": "Sample"}],
}

openapi = OpenAPI.from_dict(SPEC)

# Empty query parameter: status=
request = MockRequest(
    host_url="http://localhost",
    method="get",
    path="/api",
    args={"status": ""},
)

if hasattr(openapi, "iter_request_errors"):
    errors = list(openapi.iter_request_errors(request))
    if errors:
        print("INVALID")
        for e in errors:
            print(f"  {type(e).__name__}: {e}")
    else:
        print("VALID")
else:
    try:
        openapi.validate_request(request)
        print("VALID")
    except Exception as exc:
        print("INVALID")
        print(f"  {type(exc).__name__}: {exc}")

It prints:

INVALID
  ParameterValidationError: Query parameter error: status

Expected Behavior

It should print VALID.

OpenAPI Core Version

0.23.1

See OAI/OpenAPI-Specification#5411

Activity

  1. added
    kind/bug
    on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions