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

Offen
#1,210 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
api

Rechercherichtung

Start with the OpenAPI.from_dict and MockRequest reproduction, then trace iter_request_errors through query-parameter enum validation. Add a regression test covering status= when the enum includes an empty string, and confirm the request is accepted without a ParameterValidationError.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

kind/bug
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 https://github.com/OAI/OpenAPI-Specification/discussions/5411

Vorherrschende Sprache
Python
Sterne
368
Forks
140
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python-openapi/openapi-core

Alle Issues in python-openapi/openapi-core

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.