Skip to content

Generate maps and arrays whose additionalProperties or items is an allOf holding false as with false - #5319

Merged
Koudai Aono (koxudaxi) merged 3 commits into
fix-5310-enum-unholdablefrom
fix-5312-false-allof-values
Oct 26, 2026
Merged

Koudai Aono (koxudaxi) merged 3 commits into
fix-5310-enum-unholdablefrom
fix-5312-false-allof-values

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Fixes: #5312

Summary by CodeRabbit

  • Bug Fixes
    • Improved JSON Schema and OpenAPI model generation for schemas with allOf: false, including maps, array items, and unevaluated properties.
    • Corrected generated models to reflect when additional properties or values are disallowed.
  • Tests
    • Added coverage for validation and model generation across supported output types and OpenAPI schemas.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cacff86 and 2c6d714.

Files ignored due to path filters: 23
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[dataclasses.dataclass-false_all_of_unevaluated].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[pydantic_v2.BaseModel-false_all_of_unevaluated].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[pydantic_v2.dataclass-false_all_of_unevaluated].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unread_values.payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[dataclasses.dataclass-false_all_of_values-default].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[msgspec.Struct-false_all_of_values-default].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[msgspec.Struct-false_all_of_values-single-dict-typed-nullable-map-values].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.BaseModel-false_all_of_values-default].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.BaseModel-false_all_of_values-single-dict-typed-nullable-map-values].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.dataclass-false_all_of_values-default].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.dataclass-false_all_of_values-single-dict-typed-nullable-map-values].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[typing.TypedDict-false_all_of_values-default].payloads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/jsonschema/object_maps/false_all_of_nested_annotated.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/object_maps/false_all_of_unevaluated.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/object_maps/false_all_of_unread.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/object_maps/false_all_of_values.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/object_maps/false_unevaluated.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/object_maps/false_values.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/openapi/false_all_of_values.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/openapi/false_values.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/payloads/object_maps/false_all_of_unevaluated.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/payloads/object_maps/false_all_of_unread.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/payloads/object_maps/false_all_of_values.json is excluded by !tests/data/**/*.json and included by none
Files selected for processing: 26
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/parser/openapi.py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[dataclasses.dataclass-false_all_of_unevaluated].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[msgspec.Struct-false_all_of_unevaluated].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[pydantic_v2.BaseModel-false_all_of_unevaluated].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[pydantic_v2.dataclass-false_all_of_unevaluated].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unevaluated_properties[typing.TypedDict-false_all_of_unevaluated].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_unread_values.py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[dataclasses.dataclass-false_all_of_values-default].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[msgspec.Struct-false_all_of_values-default].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[msgspec.Struct-false_all_of_values-single-dict-typed-nullable-map-values].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.BaseModel-false_all_of_values-default].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.BaseModel-false_all_of_values-single-dict-typed-nullable-map-values].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.dataclass-false_all_of_values-default].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[pydantic_v2.dataclass-false_all_of_values-single-dict-typed-nullable-map-values].py
  • tests/data/expected/main/jsonschema/object_maps/false_all_of_values[typing.TypedDict-false_all_of_values-default].py
  • tests/data/expected/main/jsonschema/object_maps/nested_false_all_of_annotated_value.py
  • tests/data/expected/main/openapi/main_openapi/false_all_of_values[false_all_of_values].py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/jsonschema/test_object_maps.py
  • tests/main/jsonschema/test_object_maps.refs
  • tests/main/openapi/test_main_openapi.py
  • tests/main/openapi/test_main_openapi.refs
  • tests/main/test_error_messages.py
  • tests/main/test_payload_validation.refs
  • tests/test_yaml_fast_constructor.refs
Files with no reviewable changes: 1
  • tests/main/jsonschema/test_main_jsonschema.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

Walkthrough

The JSON Schema parser now normalizes false-valued allOf constraints in selected map and array value schemas, including reference and unevaluated-property paths. OpenAPI parsing applies the same normalization to schemas and parameters. Regression tests and generated snapshots cover model generation and validation behavior.

Changes: False allOf schema handling

Layer / File(s) Summary
Normalize false allOf values in JSON Schema parsing
src/datamodel_code_generator/parser/jsonschema.py
The parser recognizes false-valued allOf schemas and normalizes selected map values and array items. It applies normalization during reference analysis and schema parsing, and adjusts unevaluated-property conversion and object-map warnings.
Apply normalization to OpenAPI schemas
src/datamodel_code_generator/parser/openapi.py, tests/main/openapi/*, tests/data/expected/main/openapi/*, tests/main/test_payload_validation.refs, tests/test_yaml_fast_constructor.refs
OpenAPI schema and parameter parsing applies the normalization. Tests and snapshots cover schemas, paths, parameters, and request bodies.
Cover JSON Schema object-map and array cases
tests/main/jsonschema/*, tests/data/expected/main/jsonschema/object_maps/*, tests/main/test_payload_validation.refs, tests/main/test_error_messages.py
Regression tests and generated fixtures cover false-valued map and array constraints, unevaluated properties, and multiple output model types. Tests compare generated-model validation with JSON Schema validation.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to 2c6d7

No actionable regression remains from this change; it is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately describes the main change: generating maps and arrays when additionalProperties or items contains an allOf schema with false.
Linked Issues check Passed [#5312] Requirement: when additionalProperties or items is an allOf holding false, generation must succeed and treat the value like false, so only an empty map or array is valid. Evidence: t…
Out of Scope Changes check Passed The changes center on one concept: normalizing allOf schemas that hold false. The PR objectives report that the author applies this handling to sites beyond the literal issue text (properties, map…
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 19 files. (6 skipped: 4…
Full details: Linked Issues check

Explanation

[#5312] Requirement: when additionalProperties or items is an allOf holding false, generation must succeed and treat the value like false, so only an empty map or array is valid. Evidence: the summary says _read_false_all_of_values normalizes false-allOf schemas that govern map values or array items, and it runs during reference-graph analysis and schema parsing. The included expected outputs for false_all_of_values (default and single-dict typed-nullable-map-values variants, for pydantic_v2, dataclasses, msgspec, and TypedDict) and the OpenAPI expected output false_all_of_values[false_all_of_values].py show the issue form generating without the unsatisfiable error. Map fields are typed as empty-only (max_length=0 or an Empty/Nothing alias), and list fields are typed as zero-length, which matches the requested behavior. tests/main/jsonschema/test_object_maps.py and tests/main/openapi/test_main_openapi.py add automated coverage that compares this generated output. Limits: the JSON and YAML input fixtures and the payload .txt files are excluded by ignored-file rules, so I could not confirm their exact content. The verdict relies on the included expected .py outputs and test code. I did not run the test suite. The claim that the expected outputs match the code path rests on the AI-generated summary, not on source I read directly.

Full details: Out of Scope Changes check

Explanation

The changes center on one concept: normalizing allOf schemas that hold false. The PR objectives report that the author applies this handling to sites beyond the literal issue text (properties, map values, array items, definitions, OpenAPI body and parameter schemas, the request-response walk, --read-unevaluated-properties and unevaluatedProperties, and the inexact-object-map warning). These sites use the same false-allOf rule, so they connect to the issue's objective and are not unrelated. The change to _is_false_all_of that accepts raw dictionaries supports the same normalization. The removal of the direct-false allOf case from test_main_jsonschema_additional_properties_allof_false_schema_errors follows from the new behavior for that schema. The edit to test_error_messages.py (adding minLength: 1 to the items schema) is a test fixture adjustment within the same error-location test. The new expected-output and fixture files support the new tests. No change was shown to be unrelated to false-allOf handling. Limits: I reviewed the changes through the summary and included fixture files only, and the excluded fixture inputs were not inspected.

Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 19 files. (6 skipped: 4 unsupported, 2 too large.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T14:10:43.031421Z 63d9e7b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 47.2%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 50 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[sync] 18.4 ms 42.9 ms -57.06%
❌ test_perf_client_calls[async] 20.4 ms 46.9 ms -56.36%
❌ test_perf_complex_refs 1.2 s 2.7 s -52.95%
❌ test_perf_load_pyproject_config[config-multiple] 183.7 µs 379.2 µs -51.56%
❌ test_perf_load_pyproject_config[mapping-None] 179.7 µs 370.5 µs -51.5%
❌ test_perf_load_pyproject_config[config-None] 178.9 µs 367.1 µs -51.26%
❌ test_perf_load_pyproject_config[mapping-multiple] 185.1 µs 378.5 µs -51.09%
❌ test_perf_large_models_pydantic_v2 2 s 4.2 s -50.97%
❌ test_perf_stripe_style_pydantic_v2 1.2 s 2.5 s -50.66%
❌ test_perf_extreme_large_schema 8.9 s 18 s -50.62%
❌ test_perf_aws_style_openapi_pydantic_v2 1.3 s 2.6 s -50.2%
❌ test_perf_duplicate_names 607.2 ms 1,215.8 ms -50.06%
❌ test_perf_graphql_style_pydantic_v2 486.7 ms 970.7 ms -49.86%
❌ test_perf_scalar_root_collapsed_builtin 120.1 ms 238.1 ms -49.57%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 737.4 ms 1,460 ms -49.5%
❌ test_perf_all_options_enabled 3.7 s 7.4 s -49.42%
❌ test_perf_simple_msgspec_unset_field_rendering 85.9 ms 169.5 ms -49.35%
❌ test_perf_unique_items_runtime_scalar_validation 1.6 ms 3.1 ms -48.86%
❌ test_perf_large_models_pydantic_v2_builtin_double_quotes 891.4 ms 1,735.9 ms -48.65%
❌ test_perf_unique_items_nested_model_validation 1.7 ms 3.2 ms -48.4%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix-5312-false-allof-values (2c6d714) with fix-5310-enum-unholdable (cacff86)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…lOf holding false as with false

A map whose additionalProperties, or an array whose items, is an allOf holding false with only annotations beside it
stopped generation with "allOf contains a boolean false schema that makes the schema unsatisfiable" for every output
model type, although such a value only forbids the keys of the map or the items of the array. Each schema site
(properties, items, map values, definitions, and the OpenAPI body and parameter schemas) now reads that value as false
where it types the values: the additionalProperties of an object without properties or patternProperties, of the keys
no pattern matches under --use-single-dict-for-object-maps and of a type array under --use-typed-nullable-map-values,
and the items of an array other than a tuple of no items under --use-tuple-for-fixed-length-arrays. The output is the
one generated for false. The request-response walk reads the same sites, so a readOnly property of a member beside
false splits no class, and --read-unevaluated-properties leaves such an unevaluatedProperties where it is, as it leaves
false. Where the value types nothing (a model with properties, a map whose patterns a validator checks, a tuple of no
items) the output is unchanged, and an allOf holding false at the root or as a property value still stops generation.
0.86.0 stopped with the same error.

Fixes: #5312
…del without properties and in the warning of an inexact object map

The ty check reads a key of the dict form of an allOf holding false as a string. Under --read-unevaluated-properties,
an unevaluatedProperties that is an allOf holding false, of a schema object without properties, is read as false,
as it is where nothing else applies, so the class forbids the keys as with false instead of accepting them; with
properties the allOf is copied to additionalProperties as before. The warning that names a map whose patterns leave
keys out no longer fires for an additionalProperties that is an allOf holding false, as for false.

Refs: #5312
…ed additionalProperties member

Under --use-annotated, an additionalProperties allOf whose member is an allOf holding false reads as false at no level,
so the value-constraint merge meets the nested false. The output is unchanged; only a test now reaches that branch.

Refs: #5312
@koxudaxi
Koudai Aono (koxudaxi) merged commit 4478cff into main Oct 26, 2026
25 of 26 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fix-5312-false-allof-values branch October 26, 2026 07:48
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR makes the JSON Schema and OpenAPI parsers treat additionalProperties, items and unevaluatedProperties written as an allOf holding false, with only annotations beside it, the same as false at every site where values are typed. The updated error-message test and the removed direct-false test case suggest these shapes used to fail with an error and now produce the same models as plain false, for example maps and arrays limited to zero entries and empty models with extra forbid. Where nothing is typed with the value, such as a model that has properties, keys owned by a patternProperties validator or a tuple with no items, the tests state the output stays as it was in 0.86.0. The nested allOf case under use-annotated is also unchanged. The only removed code is internal, namely the private _is_false_all_of body and some internal parser call sites, and one inexact-map warning is no longer emitted for this case. No CLI options, defaults, templates, public API or Python version support changed, so this is a bug fix that turns previously failing schemas into correct output and not a breaking change.


This analysis was produced by the release draft workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

additionalProperties or items that are an allOf holding false stop generation as unsatisfiable

1 participant