-
We have endpoints where a path parameter can be multiple types (string, integer, boolean). These are normally used for filtering. For example:
The data type specified for Thoughts? |
Beta Was this translation helpful? Give feedback.
Answered by
rgajason
Dec 29, 2022
Replies: 1 comment 1 reply
-
You use a union type. Try a different type. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried a couple variations but wasn't able to land on the coercion that I needed to fit my needs. I think part of it is because of the lack of boolean support for path parameters, but the other part is not being able to coerce between integers/int-like items and strings (I think the docs state this, but maybe I'm just changing my interpretation of the docs after testing). For example, none of the permutations I tried allowed me to accept a path parameter that would be an integer if I passed "3" and still allow for a string if I passed "foo".
I worked around this by setting the path param data type to string and then letting Pydantic coerce from within the function: