Breaking Changes
Code Generation Changes
-
RootModel defaults use direct instantiation - RootModel fields with default values now generate
ClassName(value)instead ofClassName.model_validate(value). This produces cleaner code but changes the generated output (#2714) -
--strict-nullablenow applies to JSON Schema - The--strict-nullableoption is no longer OpenAPI-only and has been moved to Field customization options. It now also correctly respectsnullableon array items (#2713, #2727)
Custom Template Update Required
-
If you use custom Jinja2 templates that check
field.nullable, you may need to update them. Thenullablefield on JsonSchemaObject now defaults toNoneinstead ofFalse. Templates should checkfield.nullable is Trueinstead of justif field.nullable(#2715)Example change:
{# Before #} {%- if field.nullable %}...{% endif %} {# After #} {%- if field.nullable is true %}...{% endif %}
Error Handling Changes
- Formatting failures emit warning instead of error - When code formatting fails (e.g., due to black errors), the generator now emits an unformatted output with a warning instead of raising an exception. This allows code generation to succeed even when formatting tools encounter issues (#2737)
What's Changed
- Require @cli_doc marker for all CLI options by @koxudaxi in #2712
- fix: respect nullable on array items with --strict-nullable by @koxudaxi in #2713
- fix: wrap RootModel primitive defaults with default_factory by @koxudaxi in #2714
- Add --use-default-factory-for-optional-nested-models option by @koxudaxi in #2711
- Fix nullable field access in custom templates with strict_nullable by @koxudaxi in #2715
- fix: skip non-model types in __change_field_name by @koxudaxi in #2717
- Add requestBodies scope support for OpenAPI by @koxudaxi in #2716
- Fix test data backspace escape by @koxudaxi in #2718
- fix: quote forward references in recursive RootModel generic parameters by @koxudaxi in #2720
- Add force_exec_validation option to catch runtime errors across Python versions by @koxudaxi in #2719
- Add validation for extra_args in test helper functions by @koxudaxi in #2723
- Fix discriminator with allOf without Literal type for Pydantic v2 by @koxudaxi in #2722
- Fix regex_engine config not applied to RootModel generic by @koxudaxi in #2721
- Fix hostname format with field_constraints to use Field(pattern=...) by @koxudaxi in #2724
- Move --strict-nullable from OpenAPI-only to Field customization by @koxudaxi in #2727
- Run CLI doc coverage test in CI without --collect-cli-docs by @koxudaxi in #2728
- Add --use-generic-base-class option for DRY model config by @koxudaxi in #2726
- Refactor parser base post-processing for DRY and type-safe implementation by @koxudaxi in #2730
- Add --collapse-reuse-models option by @koxudaxi in #2731
- Add --field-type-collision-strategy option by @koxudaxi in #2733
- Revert "Add --field-type-collision-strategy option" by @koxudaxi in #2734
- Add --no-treat-dot-as-module option for flat output structure by @koxudaxi in #2732
- Add --field-type-collision-strategy option by @koxudaxi in #2735
- Add --use-standard-primitive-types option by @koxudaxi in #2736
- Emit unformatted output when formatting fails by @koxudaxi in #2737
- Fix aliasing of builtin type field names by @koxudaxi in #2738
- Add path filters to optimize CodeRabbit reviews by @koxudaxi in #2742
- Add --output-date-class option and date-time-local format support by @koxudaxi in #2739
- Fix custom template directory not working for included templates by @koxudaxi in #2740
- Remove unnecessary model_config from RootModel subclasses by @koxudaxi in #2741
- Fix incorrect --type-mappings examples in documentation by @koxudaxi in #2744
- Add Python 3.13 deprecation warning documentation by @koxudaxi in #2743
- Add admonition support to CLI docs and document --use-default nullable behavior by @koxudaxi in #2745
Full Changelog: 0.46.0...0.47.0