MCPcopy
hub / github.com/pydantic/pydantic / test_callable_json_schema_extra

Function test_callable_json_schema_extra

tests/test_json_schema.py:6079–6097  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6077
6078
6079def test_callable_json_schema_extra():
6080 def pop_default(s):
6081 s.pop('default')
6082
6083 class Model(BaseModel):
6084 a: int = Field(default=1, json_schema_extra=pop_default)
6085 b: Annotated[int, Field(default=2), Field(json_schema_extra=pop_default)]
6086 c: Annotated[int, Field(default=3)] = Field(json_schema_extra=pop_default)
6087
6088 assert Model().model_dump() == {'a': 1, 'b': 2, 'c': 3}
6089 assert Model(a=11, b=12, c=13).model_dump() == {
6090 'a': 11,
6091 'b': 12,
6092 'c': 13,
6093 }
6094
6095 json_schema = Model.model_json_schema()
6096 for key in 'abc':
6097 assert json_schema['properties'][key] == {'title': key.upper(), 'type': 'integer'} # default is not present
6098
6099
6100def test_callable_json_schema_extra_dataclass():

Callers

nothing calls this directly

Calls 3

ModelClass · 0.70
model_dumpMethod · 0.45
model_json_schemaMethod · 0.45

Tested by

no test coverage detected