dependabot[bot] opened a new pull request, #18956: URL: https://github.com/apache/iceberg/pull/18956
Bumps [datamodel-code-generator](https://github.com/datamodel-code-generator/datamodel-code-generator) from 0.87.0 to 0.91.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/datamodel-code-generator/datamodel-code-generator/releases">datamodel-code-generator's releases</a>.</em></p> <blockquote> <h2>0.91.0</h2> <h2>Breaking Changes</h2> <h3>Code Generation Changes</h3> <ul> <li>Empty unused classes for x-python-import schemas referenced outside <code>$defs</code> are no longer generated - Some schemas carry <code>x-python-import</code>, are reached through a JSON pointer outside <code>$defs</code> or <code>definitions</code> (for example <code>/components/Options</code> in the same file or <code>other.json</code> plus <code>/components/Options</code>), and are named only by fields. Previously such a schema was also written as an empty class that nothing used, such as <code>class Options(BaseModel): pass</code>, next to the import that types those fields. That class is now left out, which matches how these schemas are already handled in <code>$defs</code>. Fields that reference the schema still use the imported class, such as <code>OrderedDict</code>. A schema that another model uses as a base, including the subclasses made by <code>--reuse-model</code>, keeps its model. Code that imported or referenced the removed empty class from the generated modul e must be updated. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6415">#6415</a>)</li> <li>Nested model names under <code>--naming-strategy enclosing-model</code> now follow the restored owner name in modular output - When several input files each define a model with the same name (for example <code>Parent</code>), the naming plan numbers the later one across the input and its own module then gives it back its base name. Models whose names were composed from that numbered owner (inline children, grandchildren, ordinal, tagged or composed models) now also take the name composed from the restored name, e.g. <code>ParentChild</code> and <code>ParentChildGrand</code> instead of names built from the numbered owner such as <code>Parent1Child</code>, wherever the module leaves those names free. Code that imports or references the previously generated nested class names must be updated. Default naming is unaffected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6417">#6417</a>)</li> <li>Schemas with <code>items</code> or <code>prefixItems</code> but no <code>array</code> type are no longer typed as lists - <code>JsonSchemaObject.is_array</code> now treats a schema as an array only when its type is <code>array</code>, when <code>array</code> is in its type list and items are given, or when it has items but no declared type. Before, any <code>items</code> or <code>prefixItems</code> made the schema an array. A schema like <code>{"type": ["string", "null"], "items": {...}}</code> used to produce <code>list[int] | None</code> and now produces <code>str | None</code>. <code>{"type": "string", "items": ...}</code> now produces <code>str</code>. <code>{"type": ["object", "null"], "items": ..., "properties": ...}</code> now produces <code>Object | None</code> instead of a union that also included <code>list[int]</code>. <code>{"type": [&qu ot;integer", "boolean"], "prefixItems": ...}</code> now produces <code>int | bool</code> instead of <code>list[Any]</code>. The old output rejected every valid value, but the field types in generated models, root models and type aliases change, so code that relied on the old list types may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6419">#6419</a>)</li> <li>Constraints on patternProperties values are now kept on a generated type alias - For Pydantic v2 output (BaseModel and dataclass), a patternProperties value schema used to be parsed without a field, so its constraints were dropped. Now, when the dict key type rejects every key that matches none of the patterns and no value is <code>Any</code>, those constraints go on a new type alias named after the parent model with a <code>PatternProperty</code> suffix, for example <code>PArrPatternProperty = TypeAliasType("PArrPatternProperty", Annotated[list[str], Field(min_length=2)])</code>. In every mode, including the default options, this applies to the <code>minItems</code>/<code>maxItems</code> of an array value. Under <code>--field-constraints</code> and <code>--use-annotated</code> (as in the presets), it also applies to bounds, lengths and <code>pattern</code>. As a result, dict value hints change from <code>dict[constr(pattern=r'^a'), list[str]]</code> to <code>dict[co nstr(pattern=r'^a'), PArrPatternProperty]</code>, modules gain the new alias names plus <code>TypeAliasType</code>/<code>Annotated</code> imports, a Pydantic dataclass can switch to <code>@dataclass(config=ConfigDict(regex_engine="python-re"))</code> when the alias holds a lookahead pattern, and data that breaks the value's schema constraints but validated before is now rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Patterns with the same value type but different constraints now generate a union of aliases - Under <code>--field-constraints</code> or <code>--use-annotated</code>, a map whose patterns share a value type but carry different constraints used to collapse into one value type. It is now written as a union of aliases, for example <code>dict[constr(pattern=r'^a|b$'), int]</code> becomes <code>dict[constr(pattern=r'^a|b$'), OverlapPatternProperty | OverlapPatternProperty1]</code>. This also applies to root models, list items and nested maps (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Generate-schema-validators patternProperties rules now use the constrained alias - With <code>--generate-schema-validators</code>, the value type in each <code>__json_schema_pattern_properties__</code> rule now refers to the alias that holds the value's constraints. For example <code>('^x', str)</code> becomes <code>('^x', RootItemPatternProperty)</code>, where <code>RootItemPatternProperty</code> is <code>Annotated[str, Field(max_length=3, min_length=2)]</code>, so the runtime validator now rejects values that break <code>minLength</code>, <code>maxLength</code>, <code>minItems</code> and similar constraints it used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>msgspec maps under use-msgspec-meta-for-map-keys now write a single pattern value as a Meta alias - With <code>--use-msgspec-meta-for-map-keys</code>, msgspec checks the key patterns. A pattern map with one value type therefore now writes that value as an alias such as <code>PIntPatternProperty: TypeAlias = Annotated[int, Meta(ge=0)]</code> instead of the plain type, so msgspec now enforces the value's constraints. Maps with several value types keep their plain types (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Properties declared in several inline allOf members now carry the constraints of every declaration - When more than one inline <code>allOf</code> member beside a <code>$ref</code> declares the same property, for example <code>{type: string}</code> in one member and <code>{maxLength: 3}</code> in another, the generated field used to take its constraints from the first declaration only. Request and response models under <code>--read-only-write-only-model-type</code> took them from the last one. Now each declaration gets the bounds, <code>multipleOf</code> and <code>pattern</code> of all of them, so a field that was <code>str</code> becomes <code>constr(max_length=3)</code>, <code>Annotated[str, Meta(max_length=3)]</code> or <code>Field(None, max_length=3)</code>. A subclass that overrides the property also gets the combined constraints, for example <code>min_length=1</code> plus <code>max_length=3</code>, where it used to have only its own. The field keeps the type, default and description it had before. Positional tuple declarations do not get item counts, and <code>$ref</code> declarations neither receive nor pass on constraints. A new warning is emitted when the declarations have no common value for a keyword. This happens by default in every dialect and output model type, with or without <code>--intersect-allof-keywords</code> and <code>--intersect-combined-schema-keywords</code>, so generated models can now reject payloads they used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6425">#6425</a>)</li> <li>Union member classes of an allOf now redeclare shared properties with the constraints of every declaration - When an allOf holds an <code>anyOf</code> or <code>oneOf</code> and the branch and the other allOf members declare the same property with different bounds, <code>multipleOf</code> or <code>pattern</code>, the generated class for each union member now declares that property itself with all the check keywords combined. Previously the class inherited the field from its first base (Pydantic, dataclasses, TypedDict) or its last base (msgspec), so some constraints were lost. For example, <code>Inline4(Inline1, Inline3)</code> now declares <code>x: conint(ge=0, le=10) | None = None</code>, where it used to inherit only <code>conint(ge=0)</code>. Generated models now reject values they used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6426">#6426</a>)</li> <li>Some union member TypedDict classes are now written without base classes - A union member TypedDict whose redeclared key differs from a base's key is now generated as a standalone <code>TypedDict</code> with no bases. For example, <code>class Refs3(TypedDict)</code> replaces <code>class Refs3(Dog, Refs1)</code>. Code that relies on the previous class hierarchy or on static assignability to the base types may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6426">#6426</a>)</li> <li>Enum object properties written as a <code>Literal</code> now keep their schema <code>pattern</code> - When an object property declares both <code>enum</code> and <code>pattern</code> and the enum is written as a <code>Literal</code> with its constraints on the field (for example <code>--enum-field-as-literal</code> together with <code>--field-constraints</code>), the generated field now includes the pattern, e.g. <code>inline: Literal['aa', 'b'] | None = Field(None, pattern=...)</code>. Before, the pattern was silently dropped at object properties, while root models and <code>const</code> fields already kept it. This affects <code>BaseModel</code>, <code>Annotated</code> and Pydantic dataclass output. Enum values that fail the pattern used to be accepted and are now rejected at validation time. If the Rust regex engine refuses the pattern, it can now also add <code>regex_engine="python-re"</code> to the model config. With <code>--ignore-enum-constraints</code> the ou tput is unchanged, and with default options (enums written as classes) nothing changes (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6428">#6428</a>)</li> <li>Constraints beside a typed oneOf or anyOf of consts are now written on its <code>Literal</code> under <code>--field-constraints</code> - When a oneOf or anyOf of <code>const</code> values is rendered as a <code>Literal</code> and its schema declares the single type of those consts (for example <code>"type": "integer"</code> beside <code>anyOf: [{"const": 1}, {"const": 5}]</code> with <code>maximum: 3</code>), the generator now carries the sibling constraint keywords onto the generated field and onto a <code>Literal</code> root model. Before this change they were silently dropped. For example, <code>consts: Literal['a', 'bb', 'ccc'] | None = None</code> becomes <code>consts: Literal['a', 'bb', 'ccc'] | None = Field(None, min_length=2)</code>, <code>consts: Literal[1, 5] | None = Field(None, le=3)</code> is now emitted, and a <code>RootModel[Literal['a', 'bb']]</code> gains <code>root: Literal['a', 'bb'] = Field(..., max_length=1)</code>. Regenerated models now reject values that earlier generated models accepted. Untyped oneOf or anyOf schemas get no constraints, <code>--filter-literal-values</code> still drops field constraints when it has already removed the rejected values, and default output is unchanged (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6429">#6429</a>)</li> <li>msgspec now writes property-count lengths on mapping class types - For msgspec output, when a field's type is a mapping class that msgspec decodes as a dict, such as <code>dict</code> or <code>dict[str, str]</code> written by <code>--type-overrides</code> with <code>--type-overrides-replace-whole-type</code>, the schema's <code>minProperties</code>/<code>maxProperties</code> are now emitted as <code>Meta(min_length=...)</code>/<code>Meta(max_length=...)</code>, for example <code>sized: Annotated[dict, Meta(min_length=1)] | UnsetType</code>. Before, they were dropped with a "msgspec.Meta does not take min_length on dict" warning. Generated Structs now reject payloads with too few or too many keys that used to decode, and those warnings no longer appear. <code>OrderedDict</code> and <code>Counter</code> classes still get no lengths, because msgspec refuses them there (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6431">#6 431</a>)</li> <li>Defaults under <code>--use-unique-items-as-set-by-value</code> are now written as the sets their types write - Array defaults that sit where the final types write a set (the field's own list, or a set type alias inside a list, union, map or tuple position) are now generated as set literals, or as <code>frozenset(...)</code> under <code>--use-generic-container-types</code>, instead of nested lists or mutable sets; for example frozen dataclasses now emit <code>levels: frozenset[int] | None = frozenset({1})</code> instead of <code>field(default_factory=lambda: {1})</code>, and pydantic emits <code>rows: list[Row] | None = [{1, 2}]</code> where the nested items used to stay lists, so the runtime type of these default values changes (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6440">#6440</a>)</li> <li>Frozen dataclasses with frozen set defaults now hash by value - Because a frozen set default is now written as a hashable <code>frozenset</code> and not a mutable set, frozen dataclasses whose fields carry such defaults now count as hashing by value under <code>--use-unique-items-as-set-by-value</code>, so uniqueItems arrays of them change type, for example <code>limits: Sequence[Limits] | None</code> becomes <code>limits: frozenset[Limits] | None</code>, which breaks code that indexes into or relies on the order of those fields (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6440">#6440</a>)</li> <li>TypedDict <code>extra_items</code> now writes uniqueItems arrays as sets under <code>--use-unique-items-as-set</code> - When generating <code>typing.TypedDict</code> models with <code>--use-unique-items-as-set</code> (and also <code>--use-unique-items-as-set-by-value</code>), the <code>extra_items</code> type built from an <code>additionalProperties</code> schema now goes through the same uniqueItems-to-set conversion as regular fields. Arrays that declare <code>uniqueItems: true</code> are now written as <code>set[...]</code>, or <code>frozenset[...]</code> with <code>--use-generic-container-types</code>, where they used to be <code>list[...]</code> or <code>Sequence[...]</code>. This covers the array itself, anyOf/oneOf members, map values and the inner arrays of nested arrays. For example, <code>extra_items=list[int]</code> becomes <code>extra_items=set[int]</code> and <code>extra_items=dict[str, list[int]]</code> becomes <code>extra_items=dict[str, set[int]]</code>. Arrays whose items cannot be hashed, such as TypedDict items, stay lists. With <code>--reuse-model</code>, an array stays a list when a model merged into it does not declare uniqueItems. Code that treats these extra values as lists (indexing, ordering, keeping duplicates) or type-checks them against <code>list</code> may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6441">#6441</a>)</li> <li>TypedDict <code>extra_items</code> from array type lists now includes the other type list members - When an <code>additionalProperties</code> schema (or another schema read as a lightweight type) declares a type list containing <code>array</code> alongside other types, such as <code>["array", "string"]</code> or <code>["array", "integer", "null"]</code>, the generated type is now a union like <code>str | list[int]</code> or <code>int | list[int] | None</code> instead of only <code>list[int]</code>, matching the type generated for a property with the same schema; regenerated <code>typing.TypedDict</code> output accepts the strings, integers and nulls the schema allows, and code that assumed these values were always lists may need type narrowing to satisfy type checkers (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6442">#6442</a>)</li> <li>TypedDict <code>extra_items</code> now written unquoted when the classes it names already exist - When generating <code>typing.TypedDict</code> output, the <code>extra_items=</code> class keyword used to be a string whenever it named a generated class, for example <code>extra_items='list[Item]'</code>, <code>extra_items='FlaggedRequest'</code> or <code>extra_items='b.Bar | c.Baz | Near'</code>. It is now written as a plain type expression, for example <code>extra_items=list[Item]</code> or <code>extra_items=b.Bar</code>, whenever every class it names is defined by the time the class statement runs: either declared earlier in the same module or imported from another module. It stays a string only when it names the class itself or a class declared later in the same module. As a result, the runtime <code>__extra_items__</code> value is the real type instead of a forward reference, which lets Pydantic <code>TypeAdapter</code> resolve these TypedDicts where it used to fail with <co de>class-not-fully-defined</code>. Generated files change wherever this applies. Because these unquoted names are now evaluated when the class is defined, the import-cycle check also counts them, so modular TypedDict output with cross-module <code>extra_items</code> in an import cycle may now merge modules into a shared <code>_internal.py</code> (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6443">#6443</a>)</li> <li>msgspec unions of differently constrained same-type members now keep their shared constraints - With <code>--output-model-type msgspec.Struct</code>, a union of members of one type that carry different constraints, where no member carries only the constraints they all share, used to be generated with no <code>Meta(...)</code> at all. It is now generated with the constraints every member implies, written once. For example, <code>anyOf: [{type: string, minLength: 2, maxLength: 3}, {type: string, maxLength: 3, pattern: '^a'}]</code> changes from <code>str</code> to <code>Annotated[str, Meta(max_length=3)]</code>, <code>anyOf: [{type: integer, minimum: 1, maximum: 5}, {type: integer, minimum: 7}]</code> changes from <code>int</code> to <code>Annotated[int, Meta(ge=1)]</code>, and aliases such as <code>TwoBases: TypeAlias = int</code> become <code>TwoBases: TypeAlias = Annotated[int, Meta(le=100)]</code> (list items too, e.g. <code>list[Annotated[int, Meta(le=100)]]</code>). Float members also take into account the int and Decimal members that msgspec decodes as floats. The generated type annotations and aliases are different, and the models now reject payloads they used to accept that every branch of the schema rejects (e.g. <code>"abcd"</code>, <code>0</code>, <code>101</code>). The dropped-constraint warning for these fields now ends with <code>, and it keeps max_length=3, which every member implies</code> (or whichever constraints are kept). This is on by default and has no opt-out flag (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6450">#6450</a>)</li> <li>Required names beside the <code>$ref</code> of a lone allOf member now produce a site subclass under <code>--intersect-combined-schema-keywords</code> - With <code>--intersect-combined-schema-keywords</code>, a field, array item or union branch like <code>allOf: [{$ref: A, required: [id]}]</code> was generated as the referenced model <code>A</code>. Here the required names sit next to the <code>$ref</code> inside the single allOf member, and <code>A</code> accepted objects that were missing them. The required names are now read from inline allOf members as well, so the site is generated as a subclass of <code>A</code> (for example <code>RefSibling(A)</code>) that requires them. The field annotation now names a new class, and payloads such as <code>{}</code> or <code>{"name": "a"}</code> that used to validate are now rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6472">#6472</a>)</li> <li>Inline allOf members that exclude null now make the site subclass non-nullable under <code>--intersect-combined-schema-keywords</code> - With <code>--intersect-combined-schema-keywords</code>, take a site subclass built from an allOf that references a nullable model plus an inline member whose type excludes null, such as <code>allOf: [{$ref: Nullable}, {type: object, required: [id]}]</code>. It used to be written as nullable (for example <code>ObjectMember | None</code>) because only the outer schema's own type was checked for null. Inline allOf members are now checked too, so the field is annotated <code>ObjectMember</code> and a <code>null</code> payload is rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6472">#6472</a>)</li> <li>Referenced document roots with x-python-import no longer generate an unused empty model - When a <code>$ref</code> points to a whole external document whose root schema declares <code>x-python-import</code> and would generate an empty class (no fields and no root type), that empty class is no longer written next to the import; fields that reference the document keep the imported class. A root that generates a model with fields or a root type, such as a <code>RootModel</code> of a map, is written as in 0.90.0, as is a root used as a base class and the root of the input document. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6480">#6480</a>, <a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6554">#6554</a>)</li> <li>Document roots with <code>x-python-import</code> reached through a pointer no longer generate an unused empty class - When a <code>$ref</code> reaches a file's root through a definition that refers back to it, and the root has <code>x-python-import</code> and would generate an empty class, that empty class is no longer written; fields keep the imported type. A root that generates a model with fields or a root type is written as in 0.90.0. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6484">#6484</a>, <a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6554">#6554</a>)</li> <li>Plain Enum discriminator tags now also hold the raw value under <code>--use-enum-values-in-discriminator</code> - When <code>--use-enum-values-in-discriminator</code> is used and a variant is tagged by a member of a plain <code>Enum</code> (one with no value base, so not <code>StrEnum</code>, <code>IntEnum</code> or the <code>(str, Enum)</code> that <code>--use-subclass-enum</code> writes), the tag field is now written as <code>Literal[PetType.cat, 'cat']</code> instead of <code>Literal[PetType.cat]</code>. Before, the discriminated union rejected every JSON payload. It now accepts them, but a field parsed from JSON holds the plain value (for example <code>'cat'</code>) instead of the Enum member, and code that type-checks against the old annotation may need updating. Python callers that pass <code>PetType.cat</code> keep working. Enums with a value base keep <code>Literal[PetType.cat]</code>, and msgspec output is unchanged (<a href="https://redirect.github.com/datamodel-code -generator/datamodel-code-generator/issues/6495">#6495</a>)</li> <li>Discriminator removed when a plain Enum tag value collides with another variant's literal - Under <code>--use-enum-values-in-discriminator</code>, a plain Enum member tag now carries its value too. So when one variant is tagged by a plain Enum member (for example <code>Plain.int_1</code>) and another variant's tag is a literal with the same value (<code>Literal[1]</code>), the union no longer gets <code>Field(None, discriminator='k')</code> and becomes a plain union. The Enum-tagged variant's field is typed as the Enum class (<code>k: Plain</code>) instead of <code>Literal[Plain.int_1]</code> (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6495">#6495</a>)</li> <li>Discriminated <code>$ref</code> branches now take the allOf members under <code>--distribute-allof-over-unions</code> - With <code>--distribute-allof-over-unions</code> (and the 20261104 presets that enable it), a <code>$ref</code> branch of an <code>anyOf</code> or <code>oneOf</code> whose target has an OpenAPI discriminator is now expanded into one generated class per subtype, each inheriting from the subtype and carrying the allOf members beside or around the union (for example <code>Owned1(Cat)</code>, <code>Owned2(Dog)</code>). Those variants now require the members' properties, such as <code>owner</code>, instead of accepting payloads without them. Classes for later branches are renumbered in union order, so the class previously generated as <code>Owned1(Fish)</code> is now <code>Owned3(Fish)</code>. In an allOf that holds such a union, the discriminated subtypes are no longer dropped, which also changes the numbered class names there. Code that imports or references the old numbered class names, or relies on the looser validation, must be updated. Output without the option is unchanged (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6497">#6497</a>)</li> <li>Discriminated <code>$ref</code> branch classes beside an allOf are tagged by the schema they name under <code>--distribute-allof-over-unions</code> - With <code>--distribute-allof-over-unions</code> (and the 20261104 presets), the class generated for each <code>$ref</code> branch of a discriminated oneOf that sits beside an allOf used to take the branch's position as its discriminator tag (for example <code>Literal['0']</code> and <code>Literal['1']</code>, or msgspec <code>tag='0'</code>) when the discriminator had no mapping. Tagged msgspec Structs also lost their mapping key, so the union rejected every payload. These classes now take the tag of the schema the branch names: <code>Literal['Cat']</code> or the mapping key such as <code>Literal['c']</code>, and <code>tag='Cat'</code> or <code>tag='c'</code> for tagged msgspec Structs. Regenerated code therefore has different tag values, and code that builds or matches the old positional tags must be updated. Output without the option is unchanged (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6498">#6498</a>)</li> <li>Discriminator tags of <code>$ref</code> branch classes with sibling properties now use the referenced schema name - When a <code>oneOf</code> of <code>$ref</code> branches has <code>properties</code> or <code>required</code> beside it and a <code>discriminator</code> without a <code>mapping</code>, each branch's generated class (for example <code>Owned1(Cat)</code> and <code>Owned2(Dog)</code>) now types the discriminator field with the name of the schema the branch references (<code>Literal['Cat']</code>, <code>Literal['Dog']</code>) instead of the branch's position in the union (<code>Literal['0']</code>, <code>Literal['1']</code>). This affects the default output for pydantic, dataclass and msgspec models. The old output rejected every payload, so this is a fix, but any code that built or matched these models using the positional literal values has to be updated (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6499">#6499</a>)</ li> <li>Constraints an allOf site adds to its single <code>$ref</code> are now enforced in default msgspec and Pydantic dataclass output - When a property is an <code>allOf</code> of one <code>$ref</code> plus extra keywords (<code>maxLength</code> beside the allOf, <code>minItems</code> or <code>pattern</code> in a second member, or a bound beside a <code>$ref</code> that points to an allOf of one <code>$ref</code>), the default <code>msgspec.Struct</code> and <code>pydantic_v2.dataclass</code> output used to type the field by the target alone and drop the extra keywords. The field now writes them, e.g. <code>name: Annotated[Str, Meta(max_length=5)] | UnsetType = UNSET</code> instead of <code>name: Str | UnsetType = UNSET</code>. Type aliases built from such a site now carry them too, e.g. <code>Wd: TypeAlias = Annotated[Q, Meta(le=10)]</code> instead of <code>Wd: TypeAlias = Q</code>, and <code>Score = TypeAliasType("Score", Annotated[Count, Field(..., le=100)])</code> ins tead of <code>TypeAliasType("Score", Count)</code>. As with other <code>$ref</code> siblings, these keywords are also read in draft-07 and OpenAPI 3.0 schemas unless <code>--ignore-ref-siblings-by-schema-version</code> is set. Generated models now reject payloads they used to accept, such as an 11 where the site adds <code>maximum: 10</code>. Default Pydantic BaseModel output, whose field names a root model class, is unchanged, and TypedDict output writes no constraints (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6510">#6510</a>)</li> <li>Site constraints are now written under <code>--collapse-root-models</code> and <code>--use-type-alias</code> - When root-model collapse inlines the target type, or the field names a type alias, the field now gets the constraints its allOf site adds. For Pydantic this looks like <code>count: int | None = Field(None, ge=5)</code> instead of <code>count: int | None = None</code> and <code>q_allof: conint(ge=1) | None = Field(None, le=10)</code> instead of <code>q_allof: conint(ge=1) | None = None</code>. For msgspec it looks like <code>wd_prop: Annotated[int, Meta(ge=1, le=10)] | UnsetType = UNSET</code> instead of <code>Annotated[int, Meta(ge=1)]</code>. Validation is stricter: values the schema rejects are no longer accepted (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6510">#6510</a>)</li> <li>Pydantic dataclass fields wrap their type in <code>Annotated</code> to carry site constraints - A <code>pydantic_v2.dataclass</code> field that writes no <code>Field()</code> call now takes the site constraints as <code>Annotated</code> metadata, e.g. <code>count: Annotated[Count | None, Field(ge=5)] = None</code> instead of <code>count: Count | None = None</code>, and <code>id: Annotated[Id, Field(max_length=5)]</code> instead of <code>id: Id</code>. A field that already writes a <code>Field(...)</code> call gets the constraints added to that call. The field keeps its default and its place in the constructor, but code that inspects annotations sees a different shape (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6510">#6510</a>)</li> <li>Length keywords beside a union of a model and a plain string are now written on the string member - Under <code>--collapse-root-models</code> with <code>--field-constraints</code> or <code>--use-annotated</code> (as in the presets), a length keyword such as <code>maxLength</code> beside a union of a model and a plain string type used to be written on the whole field (<code>text: Item | str | None = Field(None, max_length=3)</code>), which made Pydantic raise <code>TypeError</code> for every object value. It is now written on the string member instead: <code>Item | constr(max_length=3) | None = None</code> with <code>--field-constraints</code>, or <code>O | Annotated[str, StringConstraints(max_length=3)] | None = None</code> with <code>--use-annotated</code>. The generated code gains a <code>constr</code> or <code>StringConstraints</code> import and loses the keyword from <code>Field()</code>. Object values now validate, and strings are checked the same way as before. Field met adata and the JSON schema Pydantic produces for these fields also change (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6519">#6519</a>)</li> <li>Constraints now carry through plain alias root models such as msgspec root types - The constraint walk in <code>constrained_value_type</code> used to treat only <code>TypeAliasBase</code> subclasses as aliases. It now treats any <code>DataModel</code> whose <code>form</code> is <code>"alias"</code> as one. With msgspec.Struct output, root types are written as plain assignments like <code>Level = Annotated[int, Meta(ge=1)]</code>. A reference to one of these is now followed to its underlying value type, where before it was treated like an opaque class reference. As a result, constraints declared where the type is used, such as sibling keywords next to the single <code>$ref</code> of an <code>allOf</code>, are now written on the field. For example, <code>Annotated[int, Meta(ge=1)]</code> becomes <code>Annotated[Annotated[int, Meta(ge=1)], Meta(le=10)]</code>, and a plain <code>str</code> field can become <code>Annotated[str, Meta(max_length=5)]</code>. Generated models now enforce constraints that used to be silently dropped, so data that passed validation before may now be rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6543">#6543</a>)</li> </ul> <h3>Error Handling Changes</h3> <ul> <li>New warnings for site constraints the target type cannot take - When an allOf site adds a keyword the field's type does not accept, generation now prints a warning and leaves that constraint out, e.g. <code>Pydantic does not take max_length on AwareDatetime; Model.stamp_len_prop is generated without this constraint.</code>. The msgspec 64-bit integer-limit warning now also covers fields typed by such a site. Workflows that treat these warnings as failures may be affected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6510">#6510</a>)</li> <li>New default warning for object defaults missing required model fields - When <code>--omit-incomplete-model-defaults</code> is not set and a property's object default lacks required fields of its model (its own or a base's), generation for Pydantic v2 BaseModel, Pydantic v2 dataclass and msgspec Struct output now emits one <code>UserWarning</code> listing every such field. It starts with <code>The default of Model.field</code> or <code>The defaults of ...</code>, says the generated models will reject input that leaves the property out, and suggests <code>--omit-incomplete-model-defaults</code>. Generated code does not change, and dataclass and TypedDict outputs do not warn. Builds or tests that turn warnings into errors, such as <code>-W error</code> or pytest <code>filterwarnings = error</code>, or that expect empty stderr, can now fail or see new output for these schemas (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6518">#6518 </a>)</li> </ul> <h2>New Features</h2> <h3>Presets <code>standard-py3XX-20261106</code> and <code>practical-py3XX-20261106</code></h3> <ul> <li>New dated presets for Python 3.10 to 3.15. They build on the 20261104 presets and also turn on the opt-in options below, except where an item says otherwise. Default output (no preset) does not change.</li> </ul> <h3>New options</h3> <p>Every new option is off by default and has a <code>--no-</code> form.</p> <ul> <li><code>--read-allof-parents-in-mro-order</code> - Read the allOf parents of every inherited schema in the order of the class bases, so a property that several bases declare takes the nearer base's constraints and description, also where an allOf lists a base before its own descendant. Set by the 20261106 presets.</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/datamodel-code-generator/datamodel-code-generator/blob/main/CHANGELOG.md">datamodel-code-generator's changelog</a>.</em></p> <blockquote> <h2><a href="https://github.com/datamodel-code-generator/datamodel-code-generator/releases/tag/0.91.0">0.91.0</a> - 2026-11-07</h2> <h2>Breaking Changes</h2> <h3>Code Generation Changes</h3> <ul> <li>Empty unused classes for x-python-import schemas referenced outside <code>$defs</code> are no longer generated - Some schemas carry <code>x-python-import</code>, are reached through a JSON pointer outside <code>$defs</code> or <code>definitions</code> (for example <code>/components/Options</code> in the same file or <code>other.json</code> plus <code>/components/Options</code>), and are named only by fields. Previously such a schema was also written as an empty class that nothing used, such as <code>class Options(BaseModel): pass</code>, next to the import that types those fields. That class is now left out, which matches how these schemas are already handled in <code>$defs</code>. Fields that reference the schema still use the imported class, such as <code>OrderedDict</code>. A schema that another model uses as a base, including the subclasses made by <code>--reuse-model</code>, keeps its model. Code that imported or referenced the removed empty class from the generated modul e must be updated. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6415">#6415</a>)</li> <li>Nested model names under <code>--naming-strategy enclosing-model</code> now follow the restored owner name in modular output - When several input files each define a model with the same name (for example <code>Parent</code>), the naming plan numbers the later one across the input and its own module then gives it back its base name. Models whose names were composed from that numbered owner (inline children, grandchildren, ordinal, tagged or composed models) now also take the name composed from the restored name, e.g. <code>ParentChild</code> and <code>ParentChildGrand</code> instead of names built from the numbered owner such as <code>Parent1Child</code>, wherever the module leaves those names free. Code that imports or references the previously generated nested class names must be updated. Default naming is unaffected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6417">#6417</a>)</li> <li>Schemas with <code>items</code> or <code>prefixItems</code> but no <code>array</code> type are no longer typed as lists - <code>JsonSchemaObject.is_array</code> now treats a schema as an array only when its type is <code>array</code>, when <code>array</code> is in its type list and items are given, or when it has items but no declared type. Before, any <code>items</code> or <code>prefixItems</code> made the schema an array. A schema like <code>{"type": ["string", "null"], "items": {...}}</code> used to produce <code>list[int] | None</code> and now produces <code>str | None</code>. <code>{"type": "string", "items": ...}</code> now produces <code>str</code>. <code>{"type": ["object", "null"], "items": ..., "properties": ...}</code> now produces <code>Object | None</code> instead of a union that also included <code>list[int]</code>. <code>{"type": [&qu ot;integer", "boolean"], "prefixItems": ...}</code> now produces <code>int | bool</code> instead of <code>list[Any]</code>. The old output rejected every valid value, but the field types in generated models, root models and type aliases change, so code that relied on the old list types may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6419">#6419</a>)</li> <li>Constraints on patternProperties values are now kept on a generated type alias - For Pydantic v2 output (BaseModel and dataclass), a patternProperties value schema used to be parsed without a field, so its constraints were dropped. Now, when the dict key type rejects every key that matches none of the patterns and no value is <code>Any</code>, those constraints go on a new type alias named after the parent model with a <code>PatternProperty</code> suffix, for example <code>PArrPatternProperty = TypeAliasType("PArrPatternProperty", Annotated[list[str], Field(min_length=2)])</code>. In every mode, including the default options, this applies to the <code>minItems</code>/<code>maxItems</code> of an array value. Under <code>--field-constraints</code> and <code>--use-annotated</code> (as in the presets), it also applies to bounds, lengths and <code>pattern</code>. As a result, dict value hints change from <code>dict[constr(pattern=r'^a'), list[str]]</code> to <code>dict[co nstr(pattern=r'^a'), PArrPatternProperty]</code>, modules gain the new alias names plus <code>TypeAliasType</code>/<code>Annotated</code> imports, a Pydantic dataclass can switch to <code>@dataclass(config=ConfigDict(regex_engine="python-re"))</code> when the alias holds a lookahead pattern, and data that breaks the value's schema constraints but validated before is now rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Patterns with the same value type but different constraints now generate a union of aliases - Under <code>--field-constraints</code> or <code>--use-annotated</code>, a map whose patterns share a value type but carry different constraints used to collapse into one value type. It is now written as a union of aliases, for example <code>dict[constr(pattern=r'^a|b$'), int]</code> becomes <code>dict[constr(pattern=r'^a|b$'), OverlapPatternProperty | OverlapPatternProperty1]</code>. This also applies to root models, list items and nested maps (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Generate-schema-validators patternProperties rules now use the constrained alias - With <code>--generate-schema-validators</code>, the value type in each <code>__json_schema_pattern_properties__</code> rule now refers to the alias that holds the value's constraints. For example <code>('^x', str)</code> becomes <code>('^x', RootItemPatternProperty)</code>, where <code>RootItemPatternProperty</code> is <code>Annotated[str, Field(max_length=3, min_length=2)]</code>, so the runtime validator now rejects values that break <code>minLength</code>, <code>maxLength</code>, <code>minItems</code> and similar constraints it used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>msgspec maps under use-msgspec-meta-for-map-keys now write a single pattern value as a Meta alias - With <code>--use-msgspec-meta-for-map-keys</code>, msgspec checks the key patterns. A pattern map with one value type therefore now writes that value as an alias such as <code>PIntPatternProperty: TypeAlias = Annotated[int, Meta(ge=0)]</code> instead of the plain type, so msgspec now enforces the value's constraints. Maps with several value types keep their plain types (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6424">#6424</a>)</li> <li>Properties declared in several inline allOf members now carry the constraints of every declaration - When more than one inline <code>allOf</code> member beside a <code>$ref</code> declares the same property, for example <code>{type: string}</code> in one member and <code>{maxLength: 3}</code> in another, the generated field used to take its constraints from the first declaration only. Request and response models under <code>--read-only-write-only-model-type</code> took them from the last one. Now each declaration gets the bounds, <code>multipleOf</code> and <code>pattern</code> of all of them, so a field that was <code>str</code> becomes <code>constr(max_length=3)</code>, <code>Annotated[str, Meta(max_length=3)]</code> or <code>Field(None, max_length=3)</code>. A subclass that overrides the property also gets the combined constraints, for example <code>min_length=1</code> plus <code>max_length=3</code>, where it used to have only its own. The field keeps the type, default and description it had before. Positional tuple declarations do not get item counts, and <code>$ref</code> declarations neither receive nor pass on constraints. A new warning is emitted when the declarations have no common value for a keyword. This happens by default in every dialect and output model type, with or without <code>--intersect-allof-keywords</code> and <code>--intersect-combined-schema-keywords</code>, so generated models can now reject payloads they used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6425">#6425</a>)</li> <li>Union member classes of an allOf now redeclare shared properties with the constraints of every declaration - When an allOf holds an <code>anyOf</code> or <code>oneOf</code> and the branch and the other allOf members declare the same property with different bounds, <code>multipleOf</code> or <code>pattern</code>, the generated class for each union member now declares that property itself with all the check keywords combined. Previously the class inherited the field from its first base (Pydantic, dataclasses, TypedDict) or its last base (msgspec), so some constraints were lost. For example, <code>Inline4(Inline1, Inline3)</code> now declares <code>x: conint(ge=0, le=10) | None = None</code>, where it used to inherit only <code>conint(ge=0)</code>. Generated models now reject values they used to accept (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6426">#6426</a>)</li> <li>Some union member TypedDict classes are now written without base classes - A union member TypedDict whose redeclared key differs from a base's key is now generated as a standalone <code>TypedDict</code> with no bases. For example, <code>class Refs3(TypedDict)</code> replaces <code>class Refs3(Dog, Refs1)</code>. Code that relies on the previous class hierarchy or on static assignability to the base types may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6426">#6426</a>)</li> <li>Enum object properties written as a <code>Literal</code> now keep their schema <code>pattern</code> - When an object property declares both <code>enum</code> and <code>pattern</code> and the enum is written as a <code>Literal</code> with its constraints on the field (for example <code>--enum-field-as-literal</code> together with <code>--field-constraints</code>), the generated field now includes the pattern, e.g. <code>inline: Literal['aa', 'b'] | None = Field(None, pattern=...)</code>. Before, the pattern was silently dropped at object properties, while root models and <code>const</code> fields already kept it. This affects <code>BaseModel</code>, <code>Annotated</code> and Pydantic dataclass output. Enum values that fail the pattern used to be accepted and are now rejected at validation time. If the Rust regex engine refuses the pattern, it can now also add <code>regex_engine="python-re"</code> to the model config. With <code>--ignore-enum-constraints</code> the ou tput is unchanged, and with default options (enums written as classes) nothing changes (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6428">#6428</a>)</li> <li>Constraints beside a typed oneOf or anyOf of consts are now written on its <code>Literal</code> under <code>--field-constraints</code> - When a oneOf or anyOf of <code>const</code> values is rendered as a <code>Literal</code> and its schema declares the single type of those consts (for example <code>"type": "integer"</code> beside <code>anyOf: [{"const": 1}, {"const": 5}]</code> with <code>maximum: 3</code>), the generator now carries the sibling constraint keywords onto the generated field and onto a <code>Literal</code> root model. Before this change they were silently dropped. For example, <code>consts: Literal['a', 'bb', 'ccc'] | None = None</code> becomes <code>consts: Literal['a', 'bb', 'ccc'] | None = Field(None, min_length=2)</code>, <code>consts: Literal[1, 5] | None = Field(None, le=3)</code> is now emitted, and a <code>RootModel[Literal['a', 'bb']]</code> gains <code>root: Literal['a', 'bb'] = Field(..., max_length=1)</code>. Regenerated models now reject values that earlier generated models accepted. Untyped oneOf or anyOf schemas get no constraints, <code>--filter-literal-values</code> still drops field constraints when it has already removed the rejected values, and default output is unchanged (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6429">#6429</a>)</li> <li>msgspec now writes property-count lengths on mapping class types - For msgspec output, when a field's type is a mapping class that msgspec decodes as a dict, such as <code>dict</code> or <code>dict[str, str]</code> written by <code>--type-overrides</code> with <code>--type-overrides-replace-whole-type</code>, the schema's <code>minProperties</code>/<code>maxProperties</code> are now emitted as <code>Meta(min_length=...)</code>/<code>Meta(max_length=...)</code>, for example <code>sized: Annotated[dict, Meta(min_length=1)] | UnsetType</code>. Before, they were dropped with a "msgspec.Meta does not take min_length on dict" warning. Generated Structs now reject payloads with too few or too many keys that used to decode, and those warnings no longer appear. <code>OrderedDict</code> and <code>Counter</code> classes still get no lengths, because msgspec refuses them there (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6431">#6 431</a>)</li> <li>Defaults under <code>--use-unique-items-as-set-by-value</code> are now written as the sets their types write - Array defaults that sit where the final types write a set (the field's own list, or a set type alias inside a list, union, map or tuple position) are now generated as set literals, or as <code>frozenset(...)</code> under <code>--use-generic-container-types</code>, instead of nested lists or mutable sets; for example frozen dataclasses now emit <code>levels: frozenset[int] | None = frozenset({1})</code> instead of <code>field(default_factory=lambda: {1})</code>, and pydantic emits <code>rows: list[Row] | None = [{1, 2}]</code> where the nested items used to stay lists, so the runtime type of these default values changes (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6440">#6440</a>)</li> <li>Frozen dataclasses with frozen set defaults now hash by value - Because a frozen set default is now written as a hashable <code>frozenset</code> and not a mutable set, frozen dataclasses whose fields carry such defaults now count as hashing by value under <code>--use-unique-items-as-set-by-value</code>, so uniqueItems arrays of them change type, for example <code>limits: Sequence[Limits] | None</code> becomes <code>limits: frozenset[Limits] | None</code>, which breaks code that indexes into or relies on the order of those fields (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6440">#6440</a>)</li> <li>TypedDict <code>extra_items</code> now writes uniqueItems arrays as sets under <code>--use-unique-items-as-set</code> - When generating <code>typing.TypedDict</code> models with <code>--use-unique-items-as-set</code> (and also <code>--use-unique-items-as-set-by-value</code>), the <code>extra_items</code> type built from an <code>additionalProperties</code> schema now goes through the same uniqueItems-to-set conversion as regular fields. Arrays that declare <code>uniqueItems: true</code> are now written as <code>set[...]</code>, or <code>frozenset[...]</code> with <code>--use-generic-container-types</code>, where they used to be <code>list[...]</code> or <code>Sequence[...]</code>. This covers the array itself, anyOf/oneOf members, map values and the inner arrays of nested arrays. For example, <code>extra_items=list[int]</code> becomes <code>extra_items=set[int]</code> and <code>extra_items=dict[str, list[int]]</code> becomes <code>extra_items=dict[str, set[int]]</code>. Arrays whose items cannot be hashed, such as TypedDict items, stay lists. With <code>--reuse-model</code>, an array stays a list when a model merged into it does not declare uniqueItems. Code that treats these extra values as lists (indexing, ordering, keeping duplicates) or type-checks them against <code>list</code> may need updating (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6441">#6441</a>)</li> <li>TypedDict <code>extra_items</code> from array type lists now includes the other type list members - When an <code>additionalProperties</code> schema (or another schema read as a lightweight type) declares a type list containing <code>array</code> alongside other types, such as <code>["array", "string"]</code> or <code>["array", "integer", "null"]</code>, the generated type is now a union like <code>str | list[int]</code> or <code>int | list[int] | None</code> instead of only <code>list[int]</code>, matching the type generated for a property with the same schema; regenerated <code>typing.TypedDict</code> output accepts the strings, integers and nulls the schema allows, and code that assumed these values were always lists may need type narrowing to satisfy type checkers (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6442">#6442</a>)</li> <li>TypedDict <code>extra_items</code> now written unquoted when the classes it names already exist - When generating <code>typing.TypedDict</code> output, the <code>extra_items=</code> class keyword used to be a string whenever it named a generated class, for example <code>extra_items='list[Item]'</code>, <code>extra_items='FlaggedRequest'</code> or <code>extra_items='b.Bar | c.Baz | Near'</code>. It is now written as a plain type expression, for example <code>extra_items=list[Item]</code> or <code>extra_items=b.Bar</code>, whenever every class it names is defined by the time the class statement runs: either declared earlier in the same module or imported from another module. It stays a string only when it names the class itself or a class declared later in the same module. As a result, the runtime <code>__extra_items__</code> value is the real type instead of a forward reference, which lets Pydantic <code>TypeAdapter</code> resolve these TypedDicts where it used to fail with <co de>class-not-fully-defined</code>. Generated files change wherever this applies. Because these unquoted names are now evaluated when the class is defined, the import-cycle check also counts them, so modular TypedDict output with cross-module <code>extra_items</code> in an import cycle may now merge modules into a shared <code>_internal.py</code> (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6443">#6443</a>)</li> <li>msgspec unions of differently constrained same-type members now keep their shared constraints - With <code>--output-model-type msgspec.Struct</code>, a union of members of one type that carry different constraints, where no member carries only the constraints they all share, used to be generated with no <code>Meta(...)</code> at all. It is now generated with the constraints every member implies, written once. For example, <code>anyOf: [{type: string, minLength: 2, maxLength: 3}, {type: string, maxLength: 3, pattern: '^a'}]</code> changes from <code>str</code> to <code>Annotated[str, Meta(max_length=3)]</code>, <code>anyOf: [{type: integer, minimum: 1, maximum: 5}, {type: integer, minimum: 7}]</code> changes from <code>int</code> to <code>Annotated[int, Meta(ge=1)]</code>, and aliases such as <code>TwoBases: TypeAlias = int</code> become <code>TwoBases: TypeAlias = Annotated[int, Meta(le=100)]</code> (list items too, e.g. <code>list[Annotated[int, Meta(le=100)]]</code>). Float members also take into account the int and Decimal members that msgspec decodes as floats. The generated type annotations and aliases are different, and the models now reject payloads they used to accept that every branch of the schema rejects (e.g. <code>"abcd"</code>, <code>0</code>, <code>101</code>). The dropped-constraint warning for these fields now ends with <code>, and it keeps max_length=3, which every member implies</code> (or whichever constraints are kept). This is on by default and has no opt-out flag (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6450">#6450</a>)</li> <li>Required names beside the <code>$ref</code> of a lone allOf member now produce a site subclass under <code>--intersect-combined-schema-keywords</code> - With <code>--intersect-combined-schema-keywords</code>, a field, array item or union branch like <code>allOf: [{$ref: A, required: [id]}]</code> was generated as the referenced model <code>A</code>. Here the required names sit next to the <code>$ref</code> inside the single allOf member, and <code>A</code> accepted objects that were missing them. The required names are now read from inline allOf members as well, so the site is generated as a subclass of <code>A</code> (for example <code>RefSibling(A)</code>) that requires them. The field annotation now names a new class, and payloads such as <code>{}</code> or <code>{"name": "a"}</code> that used to validate are now rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6472">#6472</a>)</li> <li>Inline allOf members that exclude null now make the site subclass non-nullable under <code>--intersect-combined-schema-keywords</code> - With <code>--intersect-combined-schema-keywords</code>, take a site subclass built from an allOf that references a nullable model plus an inline member whose type excludes null, such as <code>allOf: [{$ref: Nullable}, {type: object, required: [id]}]</code>. It used to be written as nullable (for example <code>ObjectMember | None</code>) because only the outer schema's own type was checked for null. Inline allOf members are now checked too, so the field is annotated <code>ObjectMember</code> and a <code>null</code> payload is rejected (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6472">#6472</a>)</li> <li>Referenced document roots with x-python-import no longer generate an unused empty model - When a <code>$ref</code> points to a whole external document whose root schema declares <code>x-python-import</code> and would generate an empty class (no fields and no root type), that empty class is no longer written next to the import; fields that reference the document keep the imported class. A root that generates a model with fields or a root type, such as a <code>RootModel</code> of a map, is written as in 0.90.0, as is a root used as a base class and the root of the input document. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6480">#6480</a>, <a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6554">#6554</a>)</li> <li>Document roots with <code>x-python-import</code> reached through a pointer no longer generate an unused empty class - When a <code>$ref</code> reaches a file's root through a definition that refers back to it, and the root has <code>x-python-import</code> and would generate an empty class, that empty class is no longer written; fields keep the imported type. A root that generates a model with fields or a root type is written as in 0.90.0. (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6484">#6484</a>, <a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6554">#6554</a>)</li> <li>Plain Enum discriminator tags now also hold the raw value under <code>--use-enum-values-in-discriminator</code> - When <code>--use-enum-values-in-discriminator</code> is used and a variant is tagged by a member of a plain <code>Enum</code> (one with no value base, so not <code>StrEnum</code>, <code>IntEnum</code> or the <code>(str, Enum)</code> that <code>--use-subclass-enum</code> writes), the tag field is now written as <code>Literal[PetType.cat, 'cat']</code> instead of <code>Literal[PetType.cat]</code>. Before, the discriminated union rejected every JSON payload. It now accepts them, but a field parsed from JSON holds the plain value (for example <code>'cat'</code>) instead of the Enum member, and code that type-checks against the old annotation may need updating. Python callers that pass <code>PetType.cat</code> keep working. Enums with a value base keep <code>Literal[PetType.cat]</code>, and msgspec output is unchanged (<a href="https://redirect.github.com/datamodel-code -generator/datamodel-code-generator/issues/6495">#6495</a>)</li> <li>Discriminator removed when a plain Enum tag value collides with another variant's literal - Under <code>--use-enum-values-in-discriminator</code>, a plain Enum member tag now carries its value too. So when one variant is tagged by a plain Enum member (for example <code>Plain.int_1</code>) and another variant's tag is a literal with the same value (<code>Literal[1]</code>), the union no longer gets <code>Field(None, discriminator='k')</code> and becomes a plain union. The Enum-tagged variant's field is typed as the Enum class (<code>k: Plain</code>) instead of <code>Literal[Plain.int_1]</code> (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6495">#6495</a>)</li> <li>Discriminated <code>$ref</code> branches now take the allOf members under <code>--distribute-allof-over-unions</code> - With <code>--distribute-allof-over-unions</code> (and the 20261104 presets that enable it), a <code>$ref</code> branch of an <code>anyOf</code> or <code>oneOf</code> whose target has an OpenAPI discriminator is now expanded into one generated class per subtype, each inheriting from the subtype and carrying the allOf members beside or around the union (for example <code>Owned1(Cat)</code>, <code>Owned2(Dog)</code>). Those variants now require the members' properties, such as <code>owner</code>, instead of accepting payloads without them. Classes for later branches are renumbered in union order, so the class previously generated as <code>Owned1(Fish)</code> is now <code>Owned3(Fish)</code>. In an allOf that holds such a union, the discriminated subtypes are no longer dropped, which also changes the numbered class names there. Code that imports or references the old numbered class names, or relies on the looser validation, must be updated. Output without the option is unchanged (<a href="https://redirect.github.com/datamodel-code-generator/datamodel-code-generator/issues/6497">#6497</a>)</li> <li>Discriminated <code>$ref</code> branch classes beside an allOf are tagged by the schema they name under <code>--distribute-allof-over-unions</code> - With <code>--distribute-allof-over-unions</code> (and the 20261104 presets), the class generated for each <code>$ref</code> branch of a discriminated oneOf that sits beside an allOf used to take the branch's position a... _Description has been truncated_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
