You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Merge every class that inherits an enum into the enum - #6779
No actionable comments were generated in the recent review.
Walkthrough
The inherited-enum pass now processes models with their own fields. A new JSON Schema regression test checks generated models for three backends, including Pydantic enum-value validation.
The pass no longer skips models with fields before checking their enum bases. Documentation now describes enum merging for models generally, rather than only field-less models.
A regression test checks generated output for dataclasses, msgspec, and Pydantic v2. The Pydantic test also checks acceptance of listed enum values and rejection of an unlisted value.
datamodel-code-generator/datamodel-code-generator#6774 — The regression test covers an anyOf enum branch alongside object keywords. The issue also describes an option-specific failure, which this test does not establish as resolved.
This change fixes the generated class that inherited from both Enum and BaseModel, which caused a metaclass conflict on import. It adds regression coverage for three output backends. No merge-blocking risk is evident.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
Objective [#6773]: the generated module must import for an allOf over anyOf of an object $ref and an enum, with required beside it. Enum branches must not inherit BaseModel.
Stack status: Addressed o…
Review the stack members #6775 to #6778 with current evidence. Confirm that the merged stack, at head 562e4d2, generates an importable module for the issue input. Confirm that the test input file matches the issue task.json content. Conf…
Passed checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main change: the enum-merge pass now merges every class that inherits an enum, not only field-less classes. The raw summary shows that extract_inherited_enum no longer skips model…
Out of Scope Changes check
All changes introduced by #6779 relate to the fix for #6773. The modules.py change widens extract_inherited_enum to models with fields. The enum.py and enum_kind.py docstrings and `docs/archit…
Full details: Title check
Explanation
The title states the main change: the enum-merge pass now merges every class that inherits an enum, not only field-less classes. The raw summary shows that extract_inherited_enum no longer skips models with fields, and the linked issue #6773 concerns a class that inherits both Enum and BaseModel. The title is short, specific, and matches the changeset.
Full details: Out of Scope Changes check
Explanation
All changes introduced by #6779 relate to the fix for #6773. The modules.py change widens extract_inherited_enum to models with fields. The enum.py and enum_kind.py docstrings and docs/architecture.md describe that same behavior. The new regression test in test_main_jsonschema.py, its .refs snapshot, and the three generated expected output files cover the issue case across the three output model types. No change is unrelated to the issue. The excluded test input JSON is not assessed for scope. Its content is not reviewed.
Full details: Linked Issues check
Explanation
Objective [#6773]: the generated module must import for an allOf over anyOf of an object $ref and an enum, with required beside it. Enum branches must not inherit BaseModel.
Stack status: Addressed or Partially addressed cannot be confirmed. PR #6775, #6776, #6777, and #6778 are uncertain and have no current review evidence. The current PR base (70dbc6c) is the head of #6778, so the code that the current PR changes depends on that uncertain stack.
Current PR evidence (#6779, head 562e4d2): the summary states that extract_inherited_enum in src/datamodel_code_generator/parser/_passes/modules.py no longer skips models with fields. It now merges inherited enums for those models. The expected snapshots for pydantic_v2.BaseModel, msgspec.Struct, and dataclasses.dataclass show Result4 as a plain Enum (Result4(Enum)), and Result3(Detail, Result2) keeps the object branch. This supports the fix for #6773 at the current head.
Unresolved uncertainty: (1) the test input tests/data/jsonschema/allof_any_of_enum_branch_object_keywords.json is excluded by the !tests/data/**/*.json rule, so the test input is not reviewable. (2) The current PR's behavior depends on the uncertain base stack. (3) The summary is a prior model observation. No direct code inspection was made for this assessment. The generated expected output also has no import-level verification in this review.
Resolution
Review the stack members #6775 to #6778 with current evidence. Confirm that the merged stack, at head 562e4d2, generates an importable module for the issue input. Confirm that the test input file matches the issue task.json content. Confirm that the new pytest case runs and passes.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
LanguageTool
docs/architecture.md
LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.
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.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
⚠️50 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
No successful run was found on fix-mapped-allof-value-keywords (70dbc6c) during the generation of this report, so main (f16595d) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #6773
Summary by CodeRabbit