Repository navigation
Split pydantic request-response models only where their typed extra field or schema validator rules type additionalProperties - #5297
Conversation
…ield or schema validator rules type additionalProperties The request-response split walk followed the additionalProperties of every pydantic model, while the builder writes no typed extra field for an allOf holding a false schema, so the holder was asked for variants nobody generated. The walk now reads the builder's own decisions: the typed extra field's schema (_typed_extra_field_schema) and, under --generate-schema-validators, the additionalProperties the patternProperties rules type (_pattern_rule_additional_properties), including those of an inline allOf member. Fixes: #5286
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Select schemas for reference traversal src/datamodel_code_generator/parser/jsonschema.py |
Shared helpers select schema-valued additional properties for pattern rules and typed extra fields. Reference traversal uses those selections for model fields, map models, inline allOf members, and TypedDict extra items. |
Verify request/response variants tests/data/expected/main/jsonschema/read_only_write_only_typed_extras.py, tests/data/expected/main/jsonschema/read_only_write_only_typed_extras~main_read_only_write_only_typed_extras[dedupe-validators].py, tests/main/jsonschema/test_main_jsonschema.py, tests/main/jsonschema/test_main_jsonschema.refs, tests/parser/test_jsonschema.py |
Generated outputs and tests cover typed and untyped extras, pattern-property validation, request/response deduplication, and valid and invalid payloads. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- datamodel-code-generator/datamodel-code-generator#5237: The issue describes request/response splitting for additional-property schemas that are not typed in generated output.
- datamodel-code-generator/datamodel-code-generator#5290: The issue describes a TypedDict crash involving inline
allOfand additional-property schemas. - datamodel-code-generator/datamodel-code-generator#5299: The issue describes a TypedDict crash involving
patternPropertiesand schema-valuedadditionalProperties.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5243: Both changes update request/response reference discovery for typed additional-property fields.
- datamodel-code-generator/datamodel-code-generator#5287: Both changes align request/response graph traversal with TypedDict
extra_itemsand generated typed sites. - datamodel-code-generator/datamodel-code-generator#5244: Both changes include schema-validation rule types in request/response variant detection.
Suggested reviewers: ysheikh2
Merge Risk: 
Minimal · up to df173
-
No concrete issue remains that would prevent merging after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 inconclusive Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
The changes address
#5286.src/datamodel_code_generator/parser/jsonschema.pymakes request/response reference discovery follow the same typedadditionalPropertiesdecisions as model generation. The change covers schema-valuedadditionalProperties, pattern-property validation sources, inlineallOfhandling, typed extra fields, and TypedDictextra_items. The addedtest_main_read_only_write_only_typed_extrastest covers closed models beside a false schema, typed extras that require request/response variants, and validator-based output. The expected outputs cover both default and deduplicated validator cases.
Full details: Out of Scope Changes check
-
Explanation
The source change is limited to request/response reference discovery and shared
additionalPropertieseligibility and schema-selection logic. The generated expected files, snapshot registration, and parser test update support the new behavior. No unrelated production behavior or unrelated test area is shown in the whole-PR summary.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (3 skipped: 1 unsupported, 2 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 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 improve performance by 12.23%1 warning
Performance Changes
Tip Curious why performance improved? Comment 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 diff changes how the JSON Schema parser decides which children of a model can cause read-only and write-only splitting. The old boolean types_extras (true for any pydantic model with schema-valued additionalProperties) is replaced by the new helper _rw_typed_additional_properties. It returns only the additionalProperties that the typed extra field or the patternProperties validator rules actually type. The new expected output shows the effect on generated code. Closed and ClosedBesideRef, whose additionalProperties are an allOf with a false schema, now stay single classes where the old logic would have split them into Request and Response variants. Member, under generate-schema-validators, now splits into MemberRequest and MemberResponse because its allOf member additionalProperties point to a split model. These class name changes in request-response output can break user code that imports the old names. No CLI options, public API, templates, defaults or Python version support change. The only signature change is a renamed keyword on a private helper method. Content for Release NotesCode Generation Changes
This analysis was produced by the release draft workflow |
Fixes: #5286
Summary by CodeRabbit
TypedDictoutput.