Skip to content

Claim explicit and derived target names in one place - #6987

Merged
Koudai Aono (koxudaxi) merged 2 commits into
keep-what-a-loaded-document-knows-in-one-recordfrom
claim-explicit-then-derived-names-once
Nov 17, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
keep-what-a-loaded-document-knows-in-one-recordfrom
claim-explicit-then-derived-names-once

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes: #6979

Summary by CodeRabbit

  • Bug Fixes
    • Client generation now reports repeated explicit argument, method, and channel-resource names once each, in sorted order.
    • Collision diagnostics follow a consistent ordering. When a reserved method name is duplicated, the report includes only the reserved-name diagnostic.
  • Documentation
    • Added migration notes describing the updated client name-collision reporting behavior.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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.

Run configuration

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.

Changes: Name-collision reporting

Layer / File(s) Summary
Shared name-claiming logic
src/datamodel_code_generator/_target_operations.py
Target policies now specify collision diagnostic codes. The shared claim and argument_names functions allocate names and return duplicate explicit names for reporting.
Client naming integration
src/datamodel_code_generator/_client/plan.py, src/datamodel_code_generator/_client/fields.py, src/datamodel_code_generator/_client/channels.py, docs/migration/changes.md, tests/api_generation/test_client_generation.py, tests/api_generation/test_client_generation.refs
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • 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: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive 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 Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed 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):

  1. 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.py Planner.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.

  2. 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.

  3. 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.py arguments delegates to the same function. Status: Partially addressed. Message ordering and the once-per-name rule are not shown in the summaries.

  4. 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b2e902f and 3b0f624.

Files ignored due to path filters: 6

  • docs/data/migration.json is excluded by none and included by none
  • docs/data/migration/unreleased/client-name-collision-report.toml is excluded by none and included by none
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/main/generation_platform/client/name-repeats.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/generation_platform/client/cases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/generation_platform/client/name-repeats.yaml is excluded by !tests/data/**/*.yaml and included by none
Files selected for processing: 8

  • docs/migration/changes.md
  • src/datamodel_code_generator/_client/channels.py
  • src/datamodel_code_generator/_client/fields.py
  • src/datamodel_code_generator/_client/plan.py
  • src/datamodel_code_generator/_fastapi/plan.py
  • src/datamodel_code_generator/_target_operations.py
  • tests/api_generation/test_client_generation.py
  • tests/api_generation/test_client_generation.refs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T21:14:00.763158Z 3b0f624 PR opened
ℹ️ About Codex in GitHub

Your 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 57.86%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 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.

Learn more about Macro Runners

See affected benchmarks

⚡ 53 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_unique_items_runtime_scalar_validation 2.7 ms 1.5 ms +84.71%
⚡ test_perf_load_yaml_openapi_large 32.3 ms 17.8 ms +81.36%
⚡ test_perf_unique_items_nested_model_validation 2.8 ms 1.6 ms +75.87%
⚡ test_perf_client_calls[sync] 32.9 ms 18.9 ms +73.98%
⚡ test_perf_large_models_single_module_stdout 1,618.3 ms 943.1 ms +71.59%
⚡ test_perf_scalar_root_collapsed_builtin 187.3 ms 109.5 ms +71.14%
⚡ test_perf_openapi_large_pydantic_v2_builtin 1,356.7 ms 793.2 ms +71.05%
⚡ test_perf_large_models_pydantic_v2_noformat 1,381 ms 812.9 ms +69.89%
⚡ test_perf_simple_msgspec_unset_field_rendering 489.3 ms 288.1 ms +69.8%
⚡ test_perf_client_calls[async] 36.1 ms 21.5 ms +67.87%
⚡ test_perf_large_models_pydantic_v2_builtin_double_quotes 1,464.1 ms 875.8 ms +67.17%
⚡ test_perf_target_render[fastapi-small] 23.2 ms 13.9 ms +66.78%
⚡ test_perf_pydantic_field_name_resolution 2.1 ms 1.3 ms +66.2%
⚡ test_perf_graphql_style_pydantic_v2 758.8 ms 456.9 ms +66.06%
⚡ test_perf_multiple_files_input 3.6 s 2.2 s +65.84%
⚡ test_perf_aws_style_openapi_pydantic_v2 1.9 s 1.2 s +65%
⚡ test_perf_duplicate_names 917.9 ms 556.9 ms +64.82%
⚡ test_perf_simple_pydantic_v2_field_construction 9.7 ms 5.9 ms +64.5%
⚡ test_perf_target_render[client-small] 34.6 ms 21.2 ms +63.34%
⚡ test_perf_large_models_pydantic_v2_builtin 1,388.5 ms 850.7 ms +63.21%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claim-explicit-then-derived-names-once (2d09023) with keep-what-a-loaded-document-knows-in-one-record (b2e902f)2

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. 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. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit 62fdfaf into main Nov 17, 2026
30 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the claim-explicit-then-derived-names-once branch November 17, 2026 11:27
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

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

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.98.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The generated client reports a name collision once per extra use and unsorted, while the server reports each name once, sorted

1 participant