Bases: GenerateJsonSchema
Custom JSON-Schema generator.
General customization approach is described at
https://docs.pydantic.dev/latest/concepts/json_schema/#customizing-the-json-schema-generation-process
Source code in src/fractal_task_tools/_generatejsonschema.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 | class CustomGenerateJsonSchema(GenerateJsonSchema):
"""
Custom JSON-Schema generator.
General customization approach is described at
https://docs.pydantic.dev/latest/concepts/json_schema/#customizing-the-json-schema-generation-process
"""
def get_default_value(self, schema: core_schema.WithDefaultSchema) -> Any:
"""
Customize default setting
When possible, `default_factory` is used to compute the `default` value - see
https://github.com/pydantic/pydantic/issues/11622#issuecomment-2757419692.
"""
if "default" in schema:
return schema["default"]
elif "default_factory" in schema:
if schema.get("default_factory_takes_data"):
logger.warning(
"Cannot populate defaults based on "
f"default_factory={schema['default_factory']}, "
f'since {schema["default_factory_takes_data"]=}.'
)
return NoDefault
else:
return schema["default_factory"]()
else:
return NoDefault
|
Customize default setting
When possible, default_factory is used to compute the default value - see
https://github.com/pydantic/pydantic/issues/11622#issuecomment-2757419692.
Source code in src/fractal_task_tools/_generatejsonschema.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 | def get_default_value(self, schema: core_schema.WithDefaultSchema) -> Any:
"""
Customize default setting
When possible, `default_factory` is used to compute the `default` value - see
https://github.com/pydantic/pydantic/issues/11622#issuecomment-2757419692.
"""
if "default" in schema:
return schema["default"]
elif "default_factory" in schema:
if schema.get("default_factory_takes_data"):
logger.warning(
"Cannot populate defaults based on "
f"default_factory={schema['default_factory']}, "
f'since {schema["default_factory_takes_data"]=}.'
)
return NoDefault
else:
return schema["default_factory"]()
else:
return NoDefault
|