arthurio / fastapi-filter

Filter and order your endpoints
https://fastapi-filter.netlify.app/
MIT License
189 stars 26 forks source link

Swagger not showing types of filters #521

Open agusmdev opened 6 months ago

agusmdev commented 6 months ago

Hi! I started using this library and it works great. Excellent job @arthurio !

I just realized that with the latest version of Pydantic V2 the new behavior of optional fields breaks the types of the query params in the swagger documentation.

If you set your query params as "Optional" or with the notation query_param: Type | None it won't show the type on the swagger docs.

I've tried this by running the example https://github.com/arthurio/fastapi-filter/blob/main/examples/fastapi_filter_sqlalchemy.py, you'll see the only param that shows the type the only one that it's not optional: age__gte: int = Field(Query(description="this is a nice description")). If you change this param to be optional (age__gte: Optional[int] = Field(Query(description="this is a nice description"))) the type disappears

Without Optional:

Captura de pantalla 2023-12-13 a la(s) 10 08 52

With Optional:

Captura de pantalla 2023-12-13 a la(s) 10 09 35

Do you know a workaround or a possible fix to this?

agusmdev commented 6 months ago

It seems it's a FastAPI issue that happens when using Pydantic V2. They already know about this: https://github.com/pydantic/pydantic/issues/6647 and it seems the workaround is to use SkipJsonSchema from pydantic

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.