github koxudaxi/datamodel-code-generator 0.69.0

one day ago

Breaking Changes

  • Discriminated unions with duplicate or unresolvable discriminator values now fall back to a plain union - When a discriminated union contains variants that resolve to the same discriminator value, or variants that are containers, RootModel/type-alias wrappers, None/str members, or otherwise lack a resolvable discriminator literal, the generator no longer emits Field(..., discriminator='...') and instead produces a regular union. Previously such schemas emitted a discriminator= argument. Users regenerating models from these schemas will see the discriminator keyword removed from the affected fields (#3603)
# Before (invalid duplicate-value discriminator was emitted):
class GroupedItem(RootModel[Item | ItemReference]):
    root: Item | ItemReference = Field(..., discriminator='type')

# After (falls back to a plain union when variants are not valid discriminated members):
class MixedItem(RootModel[str | ItemReference | None]):
    root: str | ItemReference | None

What's Changed

New Contributors

Full Changelog: 0.68.1...0.69.0

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

NewReleases is sending notifications on new releases.