Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cli-reference/model-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -5029,7 +5029,7 @@ where optional fields have defaults but cannot accept `None` values.


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-reference/template-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ helps maintain consistency with codebases that prefer double-quote formatting.


class Zoom(BaseModel):
__root__: confloat(ge=0.0, le=25.0)
__root__: confloat(ge=0.0, le=25.0) = 0
```

---
Expand Down
4 changes: 2 additions & 2 deletions docs/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6182,7 +6182,7 @@ where optional fields have defaults but cannot accept `None` values.


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down Expand Up @@ -19238,7 +19238,7 @@ helps maintain consistency with codebases that prefer double-quote formatting.


class Zoom(BaseModel):
__root__: confloat(ge=0.0, le=25.0)
__root__: confloat(ge=0.0, le=25.0) = 0
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comme
{%- else %}
__root__: {{ field.type_hint }}
{%- endif %}
{%- if not field.has_default_factory_in_field and not (field.required or (field.represented_default == 'None' and field.strip_default_none))
{%- if not field.has_default_factory_in_field and not ((field.required and not field.has_default) or (field.represented_default == 'None' and field.strip_default_none))
%} = {{ field.represented_default }}
{%- endif -%}
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class {{ class_name }}({{ base_class }}{%- if fields -%}[{{get_type_hint(fields,
{%- else %}
root: {{ field.type_hint }}
{%- endif %}
{%- if not field.has_default_factory_in_field and not (field.required or (field.represented_default == 'None' and field.strip_default_none))
{%- if not field.has_default_factory_in_field and not ((field.required and not field.has_default) or (field.represented_default == 'None' and field.strip_default_none))
%} = {{ field.represented_default }}
{%- endif -%}
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ class Pitch(BaseModel):


class Zoom(BaseModel):
__root__: confloat(ge=0.0, le=25.0)
__root__: confloat(ge=0.0, le=25.0) = 0
6 changes: 3 additions & 3 deletions tests/data/expected/main/jsonschema/has_default_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class TeamType(Enum):


class ID(BaseModel):
__root__: str
__root__: str = 'abc'


class Pet(BaseModel):
name: str | None = None


class Family(BaseModel):
__root__: list[ID]
__root__: list[ID] = ['abc', 'efg']
Comment thread
koxudaxi marked this conversation as resolved.


class FamilyPets(BaseModel):
__root__: list[Pet]
__root__: list[Pet] = ['taro', 'shiro']


class Person(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/expected/main/openapi/nullable.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Email(BaseModel):


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Email(BaseModel):


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Email(BaseModel):


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/expected/main/openapi/referenced_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ModelSettingB(RootModel[confloat(ge=0.0, le=10.0)]):
root: confloat(ge=0.0, le=10.0)
root: confloat(ge=0.0, le=10.0) = 5


class Model(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ModelSettingB(RootModel[float]):
root: Annotated[float, Field(ge=0.0, le=10.0)]
root: Annotated[float, Field(ge=0.0, le=10.0)] = 5


class Model(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/expected/main/openapi/use_default_kwarg.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Email(BaseModel):


class Id(BaseModel):
__root__: int
__root__: int = 1


class Description(BaseModel):
Expand Down
Loading