Skip to content
Discussion options

You must be logged in to vote

found a workaround

from enum import Enum

from fastapi import FastAPI, Query

app = FastAPI()


class SomeValue(str, Enum):
    a = 'a'
    b = 'b'

    @classmethod
    def __modify_schema__(cls, field_schema):
        # __modify_schema__ should mutate the dict it receives in place,
        # the returned value will be ignored
        field_schema.update(
            example='b',
        )


@app.get("/")
def read_root(query_value: SomeValue):
    # Doesnt matter what happens here
    return {"Hello": "World"}

Replies: 4 comments

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
Answer selected by Kludex
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
3 participants
Converted from issue

This discussion was converted from issue #1820 on February 28, 2023 01:13.