Discussed in #882
Originally posted by zcherry17 October 24, 2022
Unless this is already a feature, I cannot find anything in the code base that supports this.
I am trying to make a schema that generates the following:
class Foo(BaseModel):
my_list: list[int] = Field(default_factory=list)
Firstly, is there a reason why default factory is not supported? If there is not any particular reason, then a default factory should be generated for arrays in some meaningful way. Perhaps if the following schema was defined, then you would get the appropriate generation.
{
"$id": "/foo",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Foo",
"type": "object",
"properties": {
"my_list": {
"type": "array",
"items": {"type": "integer"}
"default": { "default_factory": "list" }
< -- or -- >
"default_factory": "list" < -- as I have seen that extra keys are supported in the code generator -->
}
}
}
Discussed in #882
Originally posted by zcherry17 October 24, 2022
Unless this is already a feature, I cannot find anything in the code base that supports this.
I am trying to make a schema that generates the following:
Firstly, is there a reason why default factory is not supported? If there is not any particular reason, then a default factory should be generated for arrays in some meaningful way. Perhaps if the following schema was defined, then you would get the appropriate generation.
{ "$id": "/foo", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Foo", "type": "object", "properties": { "my_list": { "type": "array", "items": {"type": "integer"} "default": { "default_factory": "list" } < -- or -- > "default_factory": "list" < -- as I have seen that extra keys are supported in the code generator --> } } }