-
Path without parameters, only queries declaring an str parameter, allows to capture queries as well as defining said parameter as optional.
however q is a clumsy string alternatively:
However openapi does not have a way to say "optional query". Is there a way to force or hard code the docs? While I did read though, I'm not sure I know where to start. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hmm, I'm not sure what you want to achieve, I'm probably not understanding your use case. It might be that you're thinking that See the examples for |
Beta Was this translation helpful? Give feedback.
-
HI @tiangolo: Thanks for your quick response and fantastic work on fastapi BTW! Consider these examples:
Is there a way this would be possible? |
Beta Was this translation helpful? Give feedback.
-
I'm glad you're liking it!
Not really, that is not supported by OpenAPI, so, wouldn't show up in Swagger UI. One alternative would be to have some predefined query parameters, and have their name dynamically created, using Still, you could do it, as you found out, but it wouldn't be "documentable". |
Beta Was this translation helpful? Give feedback.
-
I get it now! Thanks! |
Beta Was this translation helpful? Give feedback.
-
Thanks for reporting back and closing the issue @yurzo ! 🚀 |
Beta Was this translation helpful? Give feedback.
I'm glad you're liking it!
Not really, that is not supported by OpenAPI, so, wouldn't show up in Swagger UI.
One alternative would be to have some predefined query parameters, and have their name dynamically created, using
Query(None, alias=some_variable_with_the_query_param_name)
. But having an arbitrary amount of query parameters that are not defined in the OpenAPI is not supported by OpenAPI.Still, you could do it, as you found out, but it wouldn't be "documentable".