2

I'm building a Python 3.10.9 FastAPI application. On my, HTTP GET single resource API endpoints, I'm accepting multiple query string elements, like this small sample:

amount__gt=1000&start_date__lt=2023-05-10

To get a query_string placeholder on the OpenAPI docs created by FastAPI I have a qs parameter. When I call the endpoint using the OpenAPI docs I get this back:

qs=amount__gt=1000&start_date__lt=2023-05-10

Which comes back as a single parameter and value. However, when calling the endpoint with PostMan, I can build up the query string with individual elements, and get back the individual parameters and values. This is how the endpoint would be called by a program. Is there a way to get FastAPI to present an unnamed parameter in the OpenAPI interface?

writes_on
  • 1,735
  • 2
  • 22
  • 35

1 Answers1

0

from fastapi import Query and then you can use this like:

async def func(amount__gt: int = Query(None), start_date__lt: int = Query(None))
Pankaj
  • 1
  • 1
  • Not really. I could do that, but have two issues. For any particular model I have many variations of the attributes (*__gt, *__eq, *__lt, *__ge, *__le, etc.) and I'd like this to be generic for any model with whatever attributes. I'm looking for a way to enter a generic query_string without the "qs" prefix. – writes_on May 09 '23 at 19:24