Remove WithJsonSchema from ExtraTemplateDataType#2868
Conversation
|
Warning Rate limit exceeded@koxudaxi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 53 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 selected for processing (1)
📝 WalkthroughWalkthroughImproves generic-type string serialization in _simple_type_name, makes ExtraTemplateDataType conditional on TYPE_CHECKING and Pydantic v2 presence, and extends jsonschema parser overrides to include several lowercase collection types with corresponding compatibility and import handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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 |
|
📚 Docs Preview: https://pr-2868.datamodel-code-generator.pages.dev |
CodSpeed Performance ReportMerging #2868 will not alter performanceComparing
|
cca2978 to
98d7f02
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2868 +/- ##
==========================================
- Coverage 99.52% 99.38% -0.14%
==========================================
Files 90 91 +1
Lines 14958 15555 +597
Branches 1791 1827 +36
==========================================
+ Hits 14887 15460 +573
- Misses 38 50 +12
- Partials 33 45 +12
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:
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/datamodel_code_generator/__main__.pysrc/datamodel_code_generator/config.pysrc/datamodel_code_generator/parser/jsonschema.py
🧰 Additional context used
🧬 Code graph analysis (2)
src/datamodel_code_generator/config.py (1)
src/datamodel_code_generator/util.py (1)
is_pydantic_v2(52-57)
src/datamodel_code_generator/parser/jsonschema.py (2)
src/datamodel_code_generator/imports.py (1)
append(74-89)src/datamodel_code_generator/parser/base.py (1)
data_type(1094-1096)
🪛 Ruff (0.14.10)
src/datamodel_code_generator/__main__.py
918-918: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ 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). (14)
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: py312-isort6 on Ubuntu
- GitHub Check: 3.12 on Windows
- GitHub Check: py312-isort5 on Ubuntu
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.11 on Ubuntu
- GitHub Check: 3.12 on Ubuntu
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.14 on Ubuntu
- GitHub Check: 3.13 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (5)
src/datamodel_code_generator/__main__.py (1)
918-924: LGTM! Correctly handles generic type serialization.The addition of
get_origincheck properly handles parameterized types likedict[str, Any], ensuring the full type representation is returned instead of just the base type name.Minor note: Line 918 has an unused
noqadirective forPLC0415since that rule isn't enabled in the project's linter configuration. However, keeping it for consistency with similar patterns throughout the file is acceptable.src/datamodel_code_generator/parser/jsonschema.py (2)
632-637: LGTM! Well-chosen Python-specific collection types.These lowercase collection types are correctly identified as requiring
x-python-typeoverride since they have no direct JSON Schema equivalents. The corresponding imports are properly defined inPYTHON_TYPE_IMPORTS(lines 584-588).
1484-1490: LGTM! Import collection logic is consistent.The logic correctly mirrors the compatibility check at lines 1400-1403, ensuring that lowercase override types found in type strings get their imports added. The condition
override_type != base_typeappropriately prevents duplicate imports when the base type itself is a lowercase override type.src/datamodel_code_generator/config.py (2)
10-10: LGTM!The removal of
WithJsonSchemafrom imports aligns with the PR objective and simplifies the dependencies.
51-56: This pattern is correct and intentional for Pydantic v2.The nested
Annotated[dict[str, Any], Field(default_factory=dict)]is valid metadata for Pydantic v2's schema generation. The commit that introduced this explicitly removed the outerWithJsonSchemaannotation, stating "automatic handling works"—meaning Pydantic v2 processes the nested Field metadata without needing explicit schema hints.Since
extra_template_datais defined asExtraTemplateDataType | None = None(lines 83, 216), the nested Field metadata correctly does not affect field initialization; it exists solely for schema generation and validation purposes. This is the intended behavior.
Breaking Change AnalysisResult: No breaking changes detected Reasoning: PR #2868 makes internal implementation changes that don't affect the public API or generated code output in breaking ways:
No CLI options, Python API signatures, generated code format, or custom template requirements were changed. This analysis was performed by Claude Code Action |
|
🎉 Released in 0.51.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.