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
Claim explicit and derived target names in one place - #6987
claim-explicit-then-derived-names-oncedatamodel-code-generator/datamodel-code-generator:claim-explicit-then-derived-names-onceCopy head branch name to clipboard
claim-explicit-then-derived-names-oncedatamodel-code-generator/datamodel-code-generator:claim-explicit-then-derived-names-onceCopy head branch name to clipboard
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Shared name-claiming logic now reports duplicate explicit names once and in sorted order. Client and server planners use the shared logic for operation, argument, and resource naming. The client migration notes and render fixture cover repeated-name reporting.
Target policies now specify collision diagnostic codes. The shared claim and argument_names functions allocate names and return duplicate explicit names for reporting.
Client method, argument, field, and channel-resource naming uses the shared functions. The migration note describes collision ordering and deduplication; the render test includes the name-repeats case.
Server naming integration src/datamodel_code_generator/_fastapi/plan.py
Server operation names, router stems, and arguments use the shared naming functions.
Issue 6976 — It concerns generated client operation-name collisions. This change updates explicit and derived name claiming, but the issue’s numbering behavior is not confirmed as addressed.
Merge Risk: Minimal · previous review 3b0f6
This change makes name-collision reporting consistent across generated clients and servers. No actionable merge-blocking risk was found.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
Objectives from #6979 (current PR #6987 and stack context):
1. Client reports each colliding operation or method name once [#6979]. Evidence: PR #6987 adds claim in _target_operations.py, which r…
Provide focused evidence that claim or its callers sort duplicate names. Show the sorted expected output in the name-repeats test fixture, which is excluded from review. Confirm that stack members #6983 to #6986 and #6988 to #6989 provi…
Passed checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "Claim explicit and derived target names in one place" matches the main change. The changeset adds a shared claim operation in _target_operations.py and routes client, FastAPI, and plann…
Out of Scope Changes check
Each non-test change in PR #6987 relates to collision reporting for explicit or derived names. Changes include: _target_operations.py (new claim, name_code, argument_names signature), `_client…
Full details: Title check
Explanation
The title "Claim explicit and derived target names in one place" matches the main change. The changeset adds a shared claim operation in _target_operations.py and routes client, FastAPI, and planner name allocation through it, so explicit and derived names are handled in one place. The title is concise, a single sentence, and specific. It does not mention the user-visible collision-reporting fix from issue #6979, but the task does not require every detail.
Full details: Out of Scope Changes check
Explanation
Each non-test change in PR #6987 relates to collision reporting for explicit or derived names. Changes include: _target_operations.py (new claim, name_code, argument_names signature), _client/channels.py, _client/fields.py, _client/plan.py, _fastapi/plan.py (shared claim path for server names and router stems), and the migration note in docs/migration/changes.md. The _fastapi/plan.py changes move the server onto the same claim path. This supports the single rule that #6979 requests for both targets. The test wiring in test_client_generation.py and .refs supports the new fixture. No unrelated change is shown in the summaries.
Full details: Linked Issues check
Explanation
Objectives from #6979 (current PR #6987 and stack context):
Client reports each colliding operation or method name once [#6979]. Evidence: PR #6987 adds claim in _target_operations.py, which returns duplicate explicit names. _client/plan.pyPlanner.named and _client/channels.py_names route names through claim. Status: Addressed by the current PR, per the file summaries. Supporting evidence is limited to summaries.
Multiple colliding names are reported in sorted order [#6979]. Evidence: The migration note in docs/migration/changes.md states sorted order. The file summaries do not show sorting in claim, argument_names, or the client planner. Status: Uncertain. Sorting is not confirmed in code evidence.
Parameter-name collisions follow the same rule for client and server [#6979]. Evidence: argument_names in _target_operations.py reports duplicates through TargetPolicy.name_code (E_NAME_COLLISION for client, F_NAME_CONFLICT for server). _fastapi/plan.pyarguments delegates to the same function. Status: Partially addressed. Message ordering and the once-per-name rule are not shown in the summaries.
AsyncAPI channel resource collisions are reported once, sorted [#6979]. Evidence: _client/channels.py_names reports duplicate configured resources from the taken result of claim. Status: Uncertain for sorting, as in item 2.
Stack context: PRs #6983, #6984, #6985, #6986 (below) and #6988, #6989 (above) have no current review evidence. The stack objectives cannot be confirmed as complete beyond the current PR's contribution.
Tests: The name-repeats expected output (tests/data/expected/main/generation_platform/client/name-repeats.txt) and its input (tests/data/generation_platform/client/name-repeats.yaml, cases.json) are in ignored_files under !tests/data/** rules. The test wiring in test_client_generation.py and .refs is visible, but the expected output cannot be checked.
Resolution
Provide focused evidence that claim or its callers sort duplicate names. Show the sorted expected output in the name-repeats test fixture, which is excluded from review. Confirm that stack members #6983 to #6986 and #6988 to #6989 provide no conflicting changes to the shared claim path.
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
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.
⚠️53 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 keep-what-a-loaded-document-knows-in-one-record (1771259) during the generation of this report, so 061ffeb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Reasoning: The PR moves client and server name claiming onto a shared claim helper in _target_operations. The behaviour diff has no accepted or violation cells, and the chosen names stay the same, so generated code does not change. The FastAPI server paths already reported each collision once, sorted, so as far as the diff shows their diagnostics are unchanged. The experimental generate-client feature is in release 0.97.0, and its diagnostics do change in three ways. First, explicit argument names, explicit method names and channel resources that repeat are now reported once per name, in sorted order, instead of once per repeat in declaration order. Second, argument collisions now come after the reserved-name and alias diagnostics, and channel resource collisions after the dotted-resource refusals. Third, an explicit method name that is a reserved member such as close, taken twice, no longer gets a collision error. These are error handling changes to a released experimental feature, so they are listed as breaking.
Content for Release Notes
Error Handling Changes
Client name collision errors are reported once per name and sorted (experimental --generate-client) - With the experimental --generate-client option, an explicit argument name (parameter_names or --aliases), an explicit method name (name of --client-operations) or a channel setting's resource that is taken three or more times is now reported in one E_NAME_COLLISION diagnostic instead of one per repeat. When several names collide, they are listed in sorted order instead of declaration order. Argument collisions now come after all reserved-name and --aliases diagnostics of the operation's parameters instead of being mixed in with them, and channel resource collisions come after the refusals of dotted resources. For example, The arguments of GET /items take 'b' twice; ... take 'a' twice becomes ... take 'a' twice; ... take 'b' twice. Tooling that matches the exact text, count or order of these error messages must be updated. Generated code is unchanged (Claim explicit and derived target names in one place #6987)
Reserved explicit method name taken twice no longer adds a collision error (experimental --generate-client) - An explicit client method name that is a reserved member name such as close, given to two operations of one resource, is now reported only as a reserved name. The extra The resource ... takes the name ... twice collision error is no longer emitted (Claim explicit and derived target names in one place #6987)
This analysis was produced by the release draft workflow
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: #6979
Summary by CodeRabbit