New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema for Literal
differs between version 2.6 and 2.7
#9402
Comments
Literal
differts between version 2.6 and 2.7 Literal
differs between version 2.6 and 2.7
Worth noting that @dmontagu raised concerns when this was introduced in #8944
Having both I'm having similar problems but in my case I am not using the pydantic/pydantic/json_schema.py Lines 778 to 780 in 4d7bef6
|
thanks for the info. I feel this should not be the case? it should either be In our case, our documentation generation script output the field |
Consider the following code example: from enum import Enum
from pydantic import BaseModel
from typing_extensions import Literal
class SpeciesEnum(str, Enum):
CAT = 'cat'
class PetWithEnum(BaseModel):
name: str
species: SpeciesEnum
class PetWithLiteral(BaseModel):
name: str
species: Literal['cat']
print(PetWithEnum.model_json_schema())
print(PetWithLiteral.model_json_schema()) Here's the raw output across 3 different Pydantic versions. Version 1.10 used
Version 2.6 used
Version 2.7 uses
In every version there is no fundamental difference between the model which uses a IMO, there probably should be more of a difference between the two setups. I would think that the There needs to be some way for me to tell Pydantic what form of output I want. Maybe it's an option, maybe it's by using Here's how the Considering the code: class SpeciesEnum1(str, Enum):
CAT = 'cat'
class SpeciesEnum2(str, Enum):
CAT = 'cat'
DOG = 'dog' Version 1.10 - both have
Version 2.6 - one has
Version 2.7 - one has both
|
According to the specification of json schema for enum and const,
From json schema perspective, it does not matter if the generated json schema is
Output of json schema:
Explicitly providing an annotation for people who actually need |
Initial Checks
Description
The schema for the fields that are marked
Literal
is different between versions 2.6 and 2.7.The version 2.7 has both
enum
andconst
as keys in the schema. See example below. Is this expected?Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: