()
| 6077 | |
| 6078 | |
| 6079 | def 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 | |
| 6100 | def test_callable_json_schema_extra_dataclass(): |
nothing calls this directly
no test coverage detected