Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApiParameter constructor does not allow schema argument? #425

Closed
foucdeg opened this issue Jun 10, 2021 · 4 comments
Closed

OpenApiParameter constructor does not allow schema argument? #425

foucdeg opened this issue Jun 10, 2021 · 4 comments

Comments

@foucdeg
Copy link

foucdeg commented Jun 10, 2021

According to OpenAPI 3.0.3 specification, the OpenAPI Parameter object accepts a schema property.

The OpenApiParameter class in this library does not seem to.

Here is what I wanted to do:

@extend_schema_view(
    list=extend_schema(
        parameters=[
            OpenApiParameter(
                name="created_after",
                required=False,
                location=OpenApiParameter.QUERY,
                description="if the object was created after this date",
                schema={"type": "string", "format": "date-time"},
            ),
            OpenApiParameter(
                name="created_before",
                required=False,
                location=OpenApiParameter.QUERY,
                description="if the object was created before or at this date",
                schema={"type": "string", "format": "date-time"},
            ),
        ]
    )
)

and I get the following error:

Unexpected keyword argument 'schema' in constructor call

@tfranzel
Copy link
Owner

tfranzel commented Jun 10, 2021

our interface is close to OpenAPI naming but not identical. please consult the docs and look at the actual parameters it supports. what you want with schema is called type because its supports multiple things, not just a raw schema.

type: Any = str,

@foucdeg
Copy link
Author

foucdeg commented Jun 10, 2021

ok, I admit I didn't think of trying type instead of schema, but I assumed type wouldn't allow me to set format because in OpenAPI they are two different properties.

Beyond the Any type hint which I missed, I fail to see where this is documented. But thanks for the answer and for your time.

@tfranzel
Copy link
Owner

i agree that the Any is sub-optimal. it's been tricky writing a good hint for these few cases. i'll add some more text as i can see how this can be confusing at first.

@tfranzel
Copy link
Owner

improved the type with 9819424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants