Repository navigation
Generate maps and arrays whose additionalProperties or items is an allOf holding false as with false - #5319
Conversation
|
No actionable comments were generated in the recent review.
|
| 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:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- --generate-schema-validators reports an additionalProperties allOf with false beside patternProperties as unsatisfiable #5296 — This issue reports the false-
allOfadditionalPropertieserror when schema validators are enabled; this change includes map-value normalization and validator-related coverage. - Other keywords holding an allOf with false still stop generation as unsatisfiable #5317 — This issue reports the same error for other schema keywords. This change covers selected map, array, and unevaluated-property cases, while the issue may include other keywords.
- TypedDict request-response models crash on an allOf map member with patternProperties beside additionalProperties reaching a readOnly model #5299 — This issue concerns request-response traversal of map-valued
additionalPropertiesinsideallOf; this change normalizes map values during parsing and reference analysis.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5313: Both changes handle false-valued
allOfconstraints in object-map rules. - datamodel-code-generator/datamodel-code-generator#5298: Both changes treat false-equivalent
allOfvalues asadditionalProperties: falsewhen determining whether a model is closed. - datamodel-code-generator/datamodel-code-generator#5297: Both changes affect selection of typed
additionalPropertiesvalues during request-response reference analysis.
Merge Risk: 
Minimal · up to 2c6d7
-
No actionable regression remains from this change; it is mergeable after normal checks.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
[
#5312] Requirement: whenadditionalPropertiesoritemsis anallOfholdingfalse, generation must succeed and treat the value likefalse, so only an empty map or array is valid. Evidence: the summary says_read_false_all_of_valuesnormalizes false-allOfschemas that govern map values or array items, and it runs during reference-graph analysis and schema parsing. The included expected outputs forfalse_all_of_values(default and single-dict typed-nullable-map-values variants, for pydantic_v2, dataclasses, msgspec, and TypedDict) and the OpenAPI expected outputfalse_all_of_values[false_all_of_values].pyshow the issue form generating without the unsatisfiable error. Map fields are typed as empty-only (max_length=0or anEmpty/Nothingalias), and list fields are typed as zero-length, which matches the requested behavior.tests/main/jsonschema/test_object_maps.pyandtests/main/openapi/test_main_openapi.pyadd automated coverage that compares this generated output. Limits: the JSON and YAML input fixtures and the payload.txtfiles are excluded by ignored-file rules, so I could not confirm their exact content. The verdict relies on the included expected.pyoutputs 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
allOfschemas that holdfalse. 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-propertiesandunevaluatedProperties, and the inexact-object-map warning). These sites use the same false-allOfrule, so they connect to the issue's objective and are not unrelated. The change to_is_false_all_ofthat accepts raw dictionaries supports the same normalization. The removal of the direct-falseallOfcase fromtest_main_jsonschema_additional_properties_allof_false_schema_errorsfollows from the new behavior for that schema. The edit totest_error_messages.py(addingminLength: 1to theitemsschema) 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-allOfhandling. 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.
Comment @coderabbitai help to get the list of available commands.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
Merging this PR will degrade performance by 47.2%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
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
a45ff0a to
c08b5f0
Compare
Breaking Change AnalysisResult: 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 |
Fixes: #5312
Summary by CodeRabbit
allOf: false, including maps, array items, and unevaluated properties.