Skip to content

Broken semantics of "required" for x-api-version header #277

@slafs

Description

@slafs

Describe the bug

The value of required attribute for the x-api-version header has changed
from true to false between versions 5.2.0 and 5.2.1.

To Reproduce

Consider this simple snippet (let's call it app.py):

from cadwyn import Cadwyn, Version, VersionBundle, VersionedAPIRouter

versions = VersionBundle(Version("2023-04-14"), Version("2022-11-16"))

app = Cadwyn(
    versions=versions,
)

router = VersionedAPIRouter()


@router.get("/foo")
def foo():
    return "foo"


app.generate_and_include_versioned_routers(router)


def test_param():
    from fastapi.testclient import TestClient

    client = TestClient(app)

    res = client.get("/openapi.json?version=2023-04-14")

    openapi_dict = res.json()

    params = openapi_dict["paths"]["/foo"]["get"]["parameters"][0]

    assert params["name"] == "x-api-version", params
    assert params["required"] is True, params

when you run it like this:

uvx --with 'cadwyn[standard]==5.2.0' pytest app.py

the test will pass, but with:

uvx --with 'cadwyn[standard]==5.2.1' pytest app.py

it fails.

Expected behavior

Even though the paramater now has a default value, I think the semantics of required in OAS 3.1 are meant for the server (not the client) to provide that default value when client omits it (because it's not required). Currently that's not what's happening, because if the client won't specify the version header, the server responds with 404 (obviously).

Additional context

I guess this is not a huge issue as I think every client code generator will add the default automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions