Fix allOf array property merging to preserve child $ref#2962
Conversation
|
Warning Rate limit exceeded@koxudaxi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 51 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes a schema merging bug where child schemas with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @tests/data/expected/main/openapi/issue_2959.py:
- Around line 1-3: The generated comment header contains a filename typo: change
the referenced filename string "issue_2953.yaml" in the top comment to
"issue_2959.yaml" so the header matches the actual file name (issue_2959.py / PR
#2959); update the second comment line to read '# filename: issue_2959.yaml'.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/datamodel_code_generator/parser/jsonschema.pytests/data/expected/main/openapi/issue_2959.pytests/main/openapi/test_main_openapi.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/main/openapi/test_main_openapi.py (1)
tests/main/conftest.py (2)
output_file(99-101)run_main_and_assert(245-409)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: 3.10 on macOS
- GitHub Check: 3.12 on macOS
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.14 on macOS
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.11 on macOS
- GitHub Check: 3.13 on macOS
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (4)
src/datamodel_code_generator/parser/jsonschema.py (1)
1871-1879: LGTM! Correctly preserves child$refduring allOf property merging.The fix appropriately checks for
$refpresence in the child dict before deciding whether to recursively merge. When a child property schema contains a$ref, it represents a complete type reference that should override the parent rather than being deep-merged, which was causing the duplicate model generation issue reported in #2959.tests/data/expected/main/openapi/issue_2959.py (1)
45-48: LGTM! Validates the fix for issue #2959.The
PaginatedDataTypeListcorrectly inherits fromCollectionWrapperand overrides thedatafield with the specificlist[DataType] | Nonetype. This confirms that the child$reftoDataTypeis properly preserved during allOf merging, rather than producing a duplicate model like the previously reportedDatumclass.tests/main/openapi/test_main_openapi.py (2)
4945-4964: LGTM! Test correctly validates the allOf array $ref preservation fix.The test structure is well-formed:
- Clear docstring explaining the regression scenario (issue #2959)
- Appropriate use of
SKIP_PYDANTIC_V1marker for Pydantic v2-specific behavior- CLI args align with the issue's reported configuration
Pending verification of the input file name discrepancy noted above.
4953-4953: The input fileissue_2953.yamlis intentionally reused for testing the fix for issue #2959. Since onlyissue_2953.yamlexists and the schema is relevant for both issues, this is not a mistake and requires no changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2962 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 94 94
Lines 17759 17761 +2
Branches 2038 2039 +1
=========================================
+ Hits 17759 17761 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is a bug fix that corrects incorrect behavior in allOf array property merging. The change ensures that when a child property contains a $ref, it completely replaces the parent property instead of incorrectly merging them. Before the fix, this merging caused duplicate model generation (e.g., creating unnecessary 'Datum' classes). The new behavior produces correct output where child $ref properly overrides parent's generic type. While regenerated code will differ for affected schemas, this represents a correction of buggy behavior rather than a breaking change - users will get correct output instead of incorrect output with duplicate models. The change is internal to the parser and does not affect any public API, CLI options, or default behaviors. This analysis was performed by Claude Code Action |
|
🎉 Released in 0.53.0 This PR is now available in the latest release. See the release notes for details. |
Fixes: #2959
Summary by CodeRabbit
Bug Fixes
$refreferences, preventing duplicate model generation when merging child properties into parent schemas.Tests
✏️ Tip: You can customize this high-level summary in your review settings.