Skip to content

Query param typed as optional enum does not render as dropdown menu in Swagger's doc #10911

Discussion options

You must be logged in to vote

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.

Replies: 1 comment 2 replies

Comment options

Kludex
Jan 9, 2024
Collaborator Sponsor

You must be logged in to vote
2 replies
@adrienballsonos
Comment options

@MasterGroosha
Comment options

Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants