3

Is it possible to create a filtering system in FastAPI like:

?something[lte]=120&something2[in]=12,34

or

?something=lte:120&something2=in:12,34

And how to make OpenAPI documentation for it?

Imagine if there are many such endpoints and even more fields? I do not want to describe a set of fields with the same type of Depends classes with a certain logic parse (I don't know how to dynamically pass type annotating for it).

It is also not possible to subclass fastapi.Query and add extra logic to it.

Also there was an idea in the implementation of the f key as a query parameter:

?f=<field_name>:<operator>:<value>&f=<field_name N>:<operator>:<value>

But in this case, the documentation is not complete and you have to fill it in description (it will also be the same for all endpoints). As a result, it will not be clear which fields can be filtered and which operators are used for them.

  • Is there only `something` and `something2`, or can it go up to `somethingN` for an unbounded `N`? – Mario Ishac Jun 20 '21 at 19:43
  • Yes, a lot of keys, a lot of parameters, a lot of endpoints, and a few operators (lte, get, le, ge, re, eq, ne, in, nin). It just seems now that it is impossible to do such multifunctional filtering. Even tried to use 1 query parameter like: ?f=::&f=:: – Kostiantyn Salnykov Jun 22 '21 at 05:36
  • Does this answer your question? [How to implement greater than or less than query parameters for FastAPI](https://stackoverflow.com/questions/71038678/how-to-implement-greater-than-or-less-than-query-parameters-for-fastapi) – Chris May 04 '23 at 15:51
  • Related answers that you might find helpful can be found [here](https://stackoverflow.com/a/70840850/17865804) and [here](https://stackoverflow.com/a/73831142/17865804) – Chris May 04 '23 at 15:52

0 Answers0