Skip to content

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

Description

@Youssef1313

Actual Behavior

Run the following code:

fromopenapi_coreimportOpenAPIfromopenapi_core.testingimportMockRequestSPEC= {
"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": ""},
)
ifhasattr(openapi, "iter_request_errors"):
errors=list(openapi.iter_request_errors(request))
iferrors:
print("INVALID")
foreinerrors:
print(f" {type(e).__name__}: {e}")
else:
print("VALID")
else:
try:
openapi.validate_request(request)
print("VALID")
exceptExceptionasexc:
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugIndicates an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions