Skip to content
Discussion options

You must be logged in to vote

My answer was incomplete. You do have to switch them around (as integers can and will be tried to be casted to strings) so it will first try to parse the integers and if that fails, it will parse it as enum (and throws an error if that fails as well). However, you need to provide the type of your path parameters like so (this is a fully working example, you can run this as-is):

from fastapi import FastAPI
from enum import Enum
app = FastAPI()

class SubType(Enum):
    thriller = "thriller"
    horror = "horror"

@app.get("/{id}-{subId:int}")
async def article_func_b(id: int, subId: int):
    return "show article with subId"

@app.get("/{id}-{subType:str}")
async def article_func_a(id: int, …

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
4 participants
Converted from issue

This discussion was converted from issue #5164 on February 27, 2023 21:47.