MCPcopy
hub / github.com/pydantic/pydantic / test_by_alias

Function test_by_alias

tests/test_json_schema.py:123–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121
122
123def test_by_alias():
124 class ApplePie(BaseModel):
125 model_config = ConfigDict(title='Apple Pie')
126 a: float = Field(alias='Snap')
127 b: int = Field(10, alias='Crackle')
128
129 assert ApplePie.model_json_schema() == {
130 'type': 'object',
131 'title': 'Apple Pie',
132 'properties': {
133 'Snap': {'type': 'number', 'title': 'Snap'},
134 'Crackle': {'type': 'integer', 'title': 'Crackle', 'default': 10},
135 },
136 'required': ['Snap'],
137 }
138 assert list(ApplePie.model_json_schema(by_alias=True)['properties'].keys()) == ['Snap', 'Crackle']
139 assert list(ApplePie.model_json_schema(by_alias=False)['properties'].keys()) == ['a', 'b']
140
141
142def test_ref_template():

Callers

nothing calls this directly

Calls 2

keysMethod · 0.80
model_json_schemaMethod · 0.45

Tested by

no test coverage detected