The simplest, straightforward answer is to fix your definition for rule.
This
class RuleChooser(BaseModel): rule: SomeRules = List[SomeRules]
says that rule is of type SomeRules and its value is a typing.List of SomeRules...which is definitely wrong because the value doesn't match the type. If you want rule to simply contain the string values of the enums, you can type it as List[str] then get all the values of the enums:
from pydantic import Field class SomeRules(str, Enum): a_rule = "something" b_rule = "something_else" class RuleChooser(BaseModel): rule: List[str] = Field(default=[rule.value for rule in SomeRules]) @app.get("/") async def root(): return RuleChooser()
$ curl http://127.0.0.1:8000 {"rule":["something","something_else"]}
Now, I'm guessing you are using the actual enum members in your app (not their string values), and you just want RuleChooser.rule to be strings only as part of the JSON response. Then, you need to again fix the definition of rule to:
from pydantic import Field class RuleChooser(BaseModel): rule: List[SomeRules] = Field(default=list(SomeRules))
which says that rule is of type typing.List of SomeRules, and its value are all the members of that Enum.
If you print an instance of RuleChooser().rule, you'll get:
[<SomeRules.a_rule: 'something'>, <SomeRules.b_rule: 'something_else'>]
But as part of the JSON response, FastAPI can handle the conversion from enum to string, and you'll get:
@app.get("/") async def root(): return RuleChooser()
$ curl http://127.0.0.1:8000 {"rule":["something","something_else"]}
which is the same as what you wanted.
{rule: ["something", "something_else"]}? Maybe it would help to show the "multiple versions" you tried.