Skip to content

How To Handle Path Parameters of Multiple Valid Types #1001

Closed Answered by rgajason
rgajason asked this question in Q&A
Discussion options

You must be logged in to vote

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:

class Widget(Document)…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rgajason
Comment options

Answer selected by JacobCoffee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants