Repository navigation
Keep one TypedDict request-response class for models an inline allOf member closes beside a schema additionalProperties - #5298
Conversation
…member closes beside a schema additionalProperties An inline allOf member with additionalProperties false closes the TypedDict, so set_additional_properties writes closed=True and no extra_items type, but the request-response split walk still collected the models that type names and asked the holder for variants nobody generated. Both now read the model's additionalProperties from one helper (_model_additional_properties), which applies the closure. Fixes: #5290
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Effective additionalProperties selection src/datamodel_code_generator/parser/jsonschema.py |
A shared helper selects False when an inline allOf source closes a model without patternProperties. The parser uses this value for extra-item metadata and request/response reference analysis. |
Closed extra-items behavior and validation tests/main/jsonschema/test_main_jsonschema.py, tests/main/jsonschema/test_main_jsonschema.refs, tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items.py, tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items~main_read_only_write_only_closed_extra_items[default].py |
Parametrized tests cover deduplicated and default request/response generation, schema validation, and msgspec decoding. Expected outputs include closed types and open types with distinct request and response extra-item types. |
Priority:
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related issues
- datamodel-code-generator/datamodel-code-generator#5237 — This PR changes effective
additionalPropertieshandling for an inlineallOfclosure; the issue also describes other schema shapes. - datamodel-code-generator/datamodel-code-generator#5286 — The issue concerns request/response reference analysis for
additionalProperties, but itsfalseschema occurs inside theadditionalPropertiespath rather than in an inlineallOfmember. - datamodel-code-generator/datamodel-code-generator#5299 — The issue concerns references from map schemas in
allOf; this PR’s helper retains the model’s own value whenpatternPropertiesis present.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5243 — Both changes update how schema-valued
additionalPropertiesaffects request/response variant detection. - datamodel-code-generator/datamodel-code-generator#5287 — Both changes alter read/write reference analysis for TypedDict
extra_items. - datamodel-code-generator/datamodel-code-generator#5242 — Both changes address request/response graph decisions for map schemas in
allOf.
Merge Risk: 
Minimal · up to b0b74
-
The change appears mergeable after normal test checks. No actionable merge-blocking issue was established.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title identifies the main change: preserving one request-response TypedDict class when an inline allOf member closes the model alongside schema-valued additionalProperties. The wording is awkward but specific and related to the changeset.
Full details: Linked Issues check
-
Explanation
Issue
#5290requires TypedDict generation to handle an inlineallOfmember withadditionalProperties: falsewhen the model also has schema-valuedadditionalProperties. The implementation centralizes this decision in_model_additional_properties.set_additional_propertiesand request/response reference analysis both use the helper. The added test and snapshots cover closed models, schema-valued extra items, and request/response generation. The expected output contains closed TypedDicts withoutextra_items, and separate request/response extra-item types where required.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#5290. The source change fixes additional-properties handling and request/response variant analysis. The test, reference entry, and generated snapshots verify the reported TypedDict generation behavior. No unrelated production behavior or unrelated test area is shown.
Full details: Docstring Coverage
-
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (3 skipped: 1 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 14.08%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! |
Breaking Change AnalysisResult: Breaking changes detected Reasoning: The PR moves the allOf-closing logic out of set_additional_properties into a new private helper, _model_additional_properties, and uses that helper in the request-response reference walk in _get_ref_schema_rw_model_reference_facts. Before, the walk read model_schema.additionalProperties directly. So a TypedDict model closed by an inline allOf member with additionalProperties false still pulled in its schema-valued additionalProperties references, and any readOnly or writeOnly fields there split the model into Request and Response variants. Now those closed models keep one class, as the new expected output shows: Closed, ClosedNested and Inner appear as single closed=True classes, while Open still splits with its extra_items type. This is a bug fix for a narrow combination of options, but it renames classes in generated output for affected schemas, so it is listed as a code generation change. The set_additional_properties refactor itself does not change behavior, because the bool branch already handled the allOf-closed case. No CLI options, public API, templates, defaults or Python version support were removed or changed. Content for Release NotesCode Generation Changes
This analysis was produced by the release draft workflow |
Fixes: #5290
Summary by CodeRabbit