Query param typed as optional enum does not render as dropdown menu in Swagger's doc #10911
Answered
by
Kludex
adrienballsonos
asked this question in
Questions
-
First Check
Commit to Help
Example Codefrom enum import Enum
from typing import Union
from fastapi import FastAPI
app = FastAPI()
class Country(str, Enum):
FIRST_COUNTRY = "firstCountry"
SECOND_COUNTRY = "secondCountry"
@app.get("/users")
def find_users(country: Union[Country, None] = None):
# filter users on country
print(f"Provided country: {country}") Description
Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.105.0 Pydantic Version2.5.2 Python Version3.9.9 Additional ContextHere is what I have when I remove the optionality of the query param: |
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jan 9, 2024
Replies: 1 comment 2 replies
-
For now, my recommendation is to do the following: from enum import Enum
from fastapi import FastAPI
from pydantic.json_schema import SkipJsonSchema
app = FastAPI()
class Country(str, Enum):
FIRST_COUNTRY = 'firstCountry'
SECOND_COUNTRY = 'secondCountry'
@app.get('/users')
def find_users(country: Country | SkipJsonSchema[None] = None):
# filter users on country
print(f'Provided country: {country}') There are already multiple discussions about this. FastAPI will solve this at some point. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For now, my recommendation is to do the following:
There are already multiple discussions about this. FastAPI will solve this at some point.