github koxudaxi/datamodel-code-generator 0.58.0

5 hours ago

New Features

  • Added --serialization-aliases for Pydantic v2 serialization alias mapping. (#3146)
  • Added --openapi-include-info-version to emit OPENAPI_INFO_VERSION from OpenAPI info.version. (#3176)
  • Added --use-object-type to generate object instead of Any for unspecified JSON Schema object and array values. (#3177)

Breaking Changes

Code Generation Changes

  • Duplicate validation aliases are now deduplicated in generated Pydantic v2 AliasChoices - Fields that previously generated duplicate entries such as AliasChoices('endDate', 'end_date', 'endDate') now generate each alias once. Runtime behavior is equivalent, but exact generated output changes. (#3146)
  • JSON Schema edge-case fixes change generated output for affected schemas - Schema-valued additionalProperties/unevaluatedProperties, const: null, complex enum values, all-false patternProperties, non-string propertyNames, boolean array item schemas, contains, minProperties/maxProperties, and enum references through allOf now generate more accurate annotations or constraints. Users with snapshots or exact-output checks may see diffs. (#3167)
  • Duplicate TypedDict import fix changes generated output - Mixed closed/open TypedDict generation no longer imports TypedDict from both typing and typing_extensions; TypedDict is kept only where required. (#3155)
  • Schema-derived payload fixes change generated output for affected schemas - Forward-referenced dict key unions, indirect $ref types in allOf, additionalProperties with $ref, heterogeneous root constraints, and unresolved discriminator fields now generate more valid types/fields. (#3168)
  • Primitive allOf schemas now generate root-style payload types - Primitive-only allOf and top-level allOf combined with oneOf/anyOf now generate RootModel/root payload types instead of empty or object-like models. Code instantiating the previous generated classes may need updates. (#3169, #3171)
  • Discriminator literal generation changed for some enum mappings - Discriminator mappings now use the resolved literal values for enum-backed mappings, including non-string values where applicable. (#3074, #3170)
  • multipleOf intersections in allOf now use the least common multiple - For example, multipleOf: 5 combined with multipleOf: 10 now generates multiple_of=10 instead of incorrectly keeping the first value. Decimal multiples are handled similarly. (#3172)
  • Schema metadata fields are now preserved automatically - contentEncoding, contentMediaType, contentSchema, externalDocs, and xml are included in generated json_schema_extra when present in the input schema, even without --model-extra-keys. (#3175)

Error Handling Changes

  • --output-datetime-class now rejects incompatible TypedDict and Dataclass output combinations - Pydantic-specific datetime classes with typing.TypedDict, and incompatible dataclass API usage, now raise errors instead of silently producing fallback output. (#3155, #3169)
  • Boolean false inside allOf now raises SchemaParseError - Unsatisfiable allOf branches are reported instead of generating incorrect models. false branches in oneOf/anyOf are filtered where appropriate. (#3168)

What's Changed

  • Create changelog updates through PRs by @koxudaxi in #3138
  • Add manual changelog update trigger by @koxudaxi in #3139
  • Update CHANGELOG for 0.57.0 by @dcg-generated-docs[bot] in #3140
  • Normalize changelog release body spacing by @koxudaxi in #3141
  • Fix duplicate changelog prepend by @koxudaxi in #3143
  • Update CHANGELOG for 0.57.0 by @dcg-generated-docs[bot] in #3144
  • Add serialization aliases by @koxudaxi in #3146
  • Sync generated docs by @dcg-generated-docs[bot] in #3148
  • Add generation dependency index by @koxudaxi in #3154
  • Document boundary payload typing by @koxudaxi in #3162
  • Sync generated docs by @dcg-generated-docs[bot] in #3163
  • Sync generated docs by @dcg-generated-docs[bot] in #3164
  • Improve code generation performance by @koxudaxi in #3166
  • Map OpenAPI Discriminator mapping's values to their real value in enums by @ilovelinux in #3074
  • Fix JSON Schema edge-case generation by @koxudaxi in #3167
  • fix(TypedDict): Issue with DateTime options not being used in the output, and duplicate TypedDict imports by @richinfante in #3155
  • Add schema-derived payload validation tests by @koxudaxi in #3168
  • Fix msgspec enum discriminator tag by @koxudaxi in #3170
  • Fix top-level allOf oneOf schema by @koxudaxi in #3171
  • Fix primitive allOf payload types by @koxudaxi in #3169
  • Fix allOf multipleOf intersection by @koxudaxi in #3172
  • Align schema feature support status by @koxudaxi in #3174
  • Support additional JSON Schema string formats by @koxudaxi in #3173
  • Add OpenAPI info version constant by @koxudaxi in #3176
  • Preserve schema metadata extras by @koxudaxi in #3175
  • Sync generated docs by @dcg-generated-docs[bot] in #3180
  • Add object type option by @koxudaxi in #3177
  • Sync generated docs by @dcg-generated-docs[bot] in #3181

New Contributors

Full Changelog: 0.57.0...0.58.0

Don't miss a new datamodel-code-generator release

NewReleases is sending notifications on new releases.