Schema generated for Literal[MyEnum.MEMBER]
is too lax?
#2535
Labels
bug V1
Bug related to Pydantic V1.X
Literal[MyEnum.MEMBER]
is too lax?
#2535
Checks
Bug
When creating a model with a property typed as
Literal[MyEnum.MEMBER]
, Pydantic generates a schema that is too lax, describing the property as being any value of the enum instead of a specific one.Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:This gives the following schema:
On the other hand, when typing the property as
Literal[MyEnum.MEMBER.value]
, the correct JSON schema is generated, accepting only the specific value. This solution though has the drawback of placing the value in the object instead of the enum member (so you loseis MyEnum.FOO
comparisons).which gives this schema:
This depends on #2534 being fixed, because we cannot even put a property typed as
Literal[MyEnum.MEMBER]
alone without the.schema()
method crashing.You can also look at a more complete example in different Pydantic versions there: https://gist.github.com/nymous/686d38ba1aa150fefe6da6d78b1cb441 (same gist as #2534).
The text was updated successfully, but these errors were encountered: