Skip to content

Revert "Add --field-type-collision-strategy option"#2734

Merged
koxudaxi merged 1 commit intomainfrom
revert-2733-feature/field-type-collision-strategy
Dec 22, 2025
Merged

Revert "Add --field-type-collision-strategy option"#2734
koxudaxi merged 1 commit intomainfrom
revert-2733-feature/field-type-collision-strategy

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Dec 22, 2025

Reverts #2733

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Removed --field-type-collision-strategy command-line option.
  • Documentation

    • Updated CLI reference documentation to reflect option removal.
  • Tests

    • Removed related test files and test cases.

✏️ Tip: You can customize this high-level summary in your review settings.

@koxudaxi koxudaxi enabled auto-merge (squash) December 22, 2025 12:18
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 22, 2025

Walkthrough

This pull request removes the FieldTypeCollisionStrategy enum and all associated field type collision handling logic across the codebase. Changes include removing CLI options, parser parameters, configuration fields, documentation, and related test cases that supported this feature.

Changes

Cohort / File(s) Change Summary
Documentation
docs/cli-reference/field-customization.md, docs/cli-reference/index.md, docs/cli-reference/quick-reference.md
Removed documentation entries and references to --field-type-collision-strategy option from all CLI reference guides and updated option counts.
Public API & Configuration
src/datamodel_code_generator/__init__.py, src/datamodel_code_generator/__main__.py, src/datamodel_code_generator/arguments.py, src/datamodel_code_generator/cli_options.py
Removed FieldTypeCollisionStrategy enum from exports, removed field_type_collision_strategy parameter from generate() function and Config model, removed CLI option metadata and argument definitions.
Parser Base & Subclasses
src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/graphql.py, src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/parser/openapi.py
Removed field_type_collision_strategy parameter from all parser constructors, removed related import, eliminated collision-based field renaming logic in favor of resolver-based approach.
Test Cases & Test Data
tests/data/expected/main/jsonschema/field_type_collision_rename_type.py, tests/data/expected/main/jsonschema/field_type_collision_rename_type_multi_model.py, tests/data/jsonschema/field_type_collision_rename_type.json, tests/data/jsonschema/field_type_collision_rename_type_multi_model.json, tests/main/jsonschema/test_main_jsonschema.py
Deleted test files for field type collision scenarios, including expected output files, input JSON schemas, and corresponding test cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Broad scope: 15+ files affected across multiple modules (documentation, API, parsers, tests)
  • Homogeneous pattern: Consistent removal pattern (same feature removed from parallel locations) reduces per-file complexity
  • Key areas requiring attention:
    • Verify that field name resolution still functions correctly after removing collision-based logic in Parser._change_field_name()
    • Confirm no dangling references to FieldTypeCollisionStrategy remain in codebase
    • Validate that all parser subclasses are properly updated and inheritance chains remain intact

Possibly related PRs

  • PR #2733: Adds the FieldTypeCollisionStrategy enum and field type collision handling logic that this PR removes—represents the inverse/opposite change to this PR.
  • PR #2711: Modifies similar parser constructors and CLI/Config surfaces; both PRs touch the same initialization paths and parameter handling in parsers and configuration.

Suggested labels

safe-to-fix

Suggested reviewers

  • ilovelinux

Poem

🐰 A cleanup hop, so neat and fine,
Field collisions fade away,
Parsers whisper sweet goodbye,
Tests retire for the day,
Our schema builders dance and sway! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: reverting a feature that added the --field-type-collision-strategy option, which is clearly demonstrated across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert-2733-feature/field-type-collision-strategy

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c416d2c and c469232.

📒 Files selected for processing (16)
  • docs/cli-reference/field-customization.md
  • docs/cli-reference/index.md
  • docs/cli-reference/quick-reference.md
  • src/datamodel_code_generator/__init__.py
  • src/datamodel_code_generator/__main__.py
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/cli_options.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/graphql.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/parser/openapi.py
  • tests/data/expected/main/jsonschema/field_type_collision_rename_type.py
  • tests/data/expected/main/jsonschema/field_type_collision_rename_type_multi_model.py
  • tests/data/jsonschema/field_type_collision_rename_type.json
  • tests/data/jsonschema/field_type_collision_rename_type_multi_model.json
  • tests/main/jsonschema/test_main_jsonschema.py
💤 Files with no reviewable changes (14)
  • docs/cli-reference/quick-reference.md
  • docs/cli-reference/field-customization.md
  • tests/data/jsonschema/field_type_collision_rename_type.json
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/cli_options.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/data/jsonschema/field_type_collision_rename_type_multi_model.json
  • tests/data/expected/main/jsonschema/field_type_collision_rename_type_multi_model.py
  • src/datamodel_code_generator/parser/openapi.py
  • src/datamodel_code_generator/main.py
  • src/datamodel_code_generator/parser/graphql.py
  • src/datamodel_code_generator/init.py
  • tests/data/expected/main/jsonschema/field_type_collision_rename_type.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/datamodel_code_generator/parser/base.py (3)
src/datamodel_code_generator/model/base.py (4)
  • base_class (668-670)
  • field (333-335)
  • name (658-660)
  • all_data_types (706-710)
src/datamodel_code_generator/reference.py (3)
  • ModelResolver (492-940)
  • reference (76-78)
  • add (775-829)
src/datamodel_code_generator/types.py (1)
  • all_data_types (424-430)
⏰ 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). (13)
  • GitHub Check: benchmarks
  • GitHub Check: 3.13 on Ubuntu
  • GitHub Check: 3.12 on macOS
  • GitHub Check: 3.10 on macOS
  • GitHub Check: 3.14 on macOS
  • GitHub Check: Analyze (python)
  • GitHub Check: 3.10 on Windows
  • GitHub Check: 3.11 on Windows
  • GitHub Check: 3.12 on Windows
  • GitHub Check: 3.11 on macOS
  • GitHub Check: 3.13 on Windows
  • GitHub Check: 3.13 on macOS
  • GitHub Check: 3.14 on Windows
🔇 Additional comments (2)
docs/cli-reference/index.md (1)

13-13: LGTM! Documentation count correctly updated.

The Field Customization option count has been properly decremented from 21 to 20, reflecting the removal of the --field-type-collision-strategy option.

src/datamodel_code_generator/parser/base.py (1)

1841-1862: LGTM! Field renaming logic correctly simplified.

The __change_field_name method has been properly reverted to use a consistent resolver-based approach. The per-field ModelResolver creation (line 1855) is intentional—each field needs independent exclusion of its own data type references to prevent shadowing issues.

The logic correctly:

  1. Skips Enum models and models without BASE_CLASS
  2. Creates a resolver with excluded reference names for each field
  3. Generates collision-free field names and sets aliases when needed

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@koxudaxi koxudaxi merged commit e8ff0f8 into main Dec 22, 2025
33 of 34 checks passed
@koxudaxi koxudaxi deleted the revert-2733-feature/field-type-collision-strategy branch December 22, 2025 12:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.36%. Comparing base (c416d2c) to head (c469232).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2734      +/-   ##
==========================================
- Coverage   99.36%   99.36%   -0.01%     
==========================================
  Files          83       83              
  Lines       12087    12068      -19     
  Branches     1457     1456       -1     
==========================================
- Hits        12010    11991      -19     
  Misses         45       45              
  Partials       32       32              
Flag Coverage Δ
unittests 99.36% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 22, 2025

CodSpeed Performance Report

Merging #2734 will not alter performance

Comparing revert-2733-feature/field-type-collision-strategy (c469232) with main (c416d2c)

Summary

✅ 70 untouched
⏩ 10 skipped1

Footnotes

  1. 10 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant