Skip to content

Add documentation for reducing duplicate field types#2896

Merged
koxudaxi merged 3 commits intomainfrom
docs/reduce-duplicate-field-types
Jan 2, 2026
Merged

Add documentation for reducing duplicate field types#2896
koxudaxi merged 3 commits intomainfrom
docs/reduce-duplicate-field-types

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Jan 2, 2026

Related to: #2155

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --use-type-alias CLI option to reduce duplicate field types by sharing type definitions across multiple classes.
  • Documentation

    • Updated CLI reference with the new --use-type-alias option.
    • New section with guidance on reducing duplicate field types using type aliases and shared definitions, including examples.
    • Enhanced cross-references throughout documentation to related topics.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 2, 2026

Warning

Rate limit exceeded

@koxudaxi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between bab0ee4 and dc4a1f4.

📒 Files selected for processing (1)
  • docs/model-reuse.md
📝 Walkthrough

Walkthrough

Added documentation for type alias deduplication feature, including guidance on using --use-type-alias with $defs and $ref. Introduced new test file demonstrating Pydantic models sharing field types via TypeAlias. Added cross-references between documentation sections.

Changes

Cohort / File(s) Summary
Documentation Updates
docs/cli-reference/typing-customization.md, docs/model-reuse.md
Added cross-reference notes and new section "Reducing Duplicate Field Types" documenting --use-type-alias option for sharing field type definitions via TypeAlias across multiple classes; includes CLI options table update and usage examples.
Test Expected Output
tests/data/expected/main/jsonschema/reduce_duplicate_field_types.py
New Pydantic module with PlaceName TypeAlias (Annotated string with Field metadata) and ClassA, ClassB models referencing it; defines composite Model TypeAlias for union of both classes.
Test Function
tests/main/jsonschema/test_main_jsonschema.py
Added test_reduce_duplicate_field_types() test function validating --use-type-alias flag functionality for reducing duplicate field types via shared TypeAlias definitions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A tale of aliases shared and neat,
Where TypeAliasType makes dedup complete,
From ClassA to ClassB they harmonize,
No duplicate types—just elegant ties,
Documentation guides all the way!

Pre-merge checks and finishing touches

✅ 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 accurately summarizes the main change: adding documentation for reducing duplicate field types, which is the primary focus across docs/model-reuse.md, docs/cli-reference/typing-customization.md, and related test files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 2, 2026

@ilovelinux ilovelinux added the documentation Improvements or additions to documentation label Jan 2, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 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 f4b240a and bab0ee4.

⛔ Files ignored due to path filters (1)
  • tests/data/jsonschema/reduce_duplicate_field_types.json is excluded by !tests/data/**/*.json and included by none
📒 Files selected for processing (4)
  • docs/cli-reference/typing-customization.md
  • docs/model-reuse.md
  • tests/data/expected/main/jsonschema/reduce_duplicate_field_types.py
  • tests/main/jsonschema/test_main_jsonschema.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/main/jsonschema/test_main_jsonschema.py (2)
tests/test_main_kr.py (1)
  • output_file (44-46)
tests/main/conftest.py (2)
  • output_file (98-100)
  • run_main_and_assert (244-408)
🪛 LanguageTool
docs/model-reuse.md

[style] ~322-~322: ‘exact same’ might be wordy. Consider a shorter alternative.
Context: ... Type safety - All fields share the exact same type ### When to Use This Pattern Thi...

(EN_WORDINESS_PREMIUM_EXACT_SAME)

🪛 markdownlint-cli2 (0.18.1)
docs/cli-reference/typing-customization.md

4201-4201: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


4201-4201: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)

docs/model-reuse.md

300-300: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

⏰ 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). (16)
  • GitHub Check: py312-black24 on Ubuntu
  • GitHub Check: 3.14 on macOS
  • GitHub Check: py312-black22 on Ubuntu
  • GitHub Check: 3.10 on macOS
  • GitHub Check: 3.10 on Ubuntu
  • GitHub Check: py312-isort7 on Ubuntu
  • GitHub Check: 3.10 on Windows
  • GitHub Check: 3.11 on macOS
  • GitHub Check: 3.14 on Windows
  • GitHub Check: 3.12 on macOS
  • GitHub Check: 3.11 on Windows
  • GitHub Check: 3.13 on macOS
  • GitHub Check: 3.12 on Windows
  • GitHub Check: 3.13 on Windows
  • GitHub Check: benchmarks
  • GitHub Check: Analyze (python)
🔇 Additional comments (10)
docs/cli-reference/typing-customization.md (1)

4201-4201: LGTM! Cross-reference improves documentation navigation.

The "See also" reference to Model Reuse and Deduplication helps users discover related functionality for the --use-type-alias option.

docs/model-reuse.md (4)

1-1: LGTM! Metadata and cross-references properly updated.

The related CLI options comment, quick overview table entry, and See Also reference for --use-type-alias are all correctly added to support the new documentation section.

Also applies to: 15-15, 339-339


247-261: Clear problem statement with effective example.

The section introduces the duplicate field types problem well, with a concrete code example showing the redundancy that --use-type-alias addresses.


263-298: Excellent step-by-step solution guide.

The JSON schema example and CLI command clearly demonstrate how to use $defs with $ref and the --use-type-alias flag to achieve type deduplication.


317-332: Comprehensive benefits and usage guidance.

The benefits clearly explain the value proposition, and the "When to Use This Pattern" section provides practical guidance for applying the feature.

tests/data/expected/main/jsonschema/reduce_duplicate_field_types.py (4)

1-10: LGTM! Standard generated file structure.

The file header, future annotations import, and type imports are all correct for demonstrating the --use-type-alias feature with Pydantic models.


12-23: Excellent demonstration of TypeAlias with Field constraints.

The PlaceName type alias correctly uses TypeAliasType with Annotated to encapsulate the field type, constraints, description, examples, and title in a single reusable definition.


26-33: Perfect example of type alias reuse across models.

Both ClassA and ClassB correctly reference the shared PlaceName type alias, eliminating the duplication that would occur with inline Annotated[str, Field(...)] definitions in each class.


36-36: LGTM! Union type alias for model variants.

The Model type alias correctly combines ClassA | ClassB as a union, demonstrating another use case for type aliases in the generated code.

tests/main/jsonschema/test_main_jsonschema.py (1)

7545-7559: New E2E test for --use-type-alias looks correct and consistent

The test wiring (schema path, expected file, input_file_type="jsonschema", and extra_args for pydantic_v2.BaseModel + --use-type-alias) matches existing patterns in this module and cleanly exercises the deduplication scenario described in the docstring. No changes needed from my side.

Comment thread docs/model-reuse.md Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jan 2, 2026

CodSpeed Performance Report

Merging #2896 will not alter performance

Comparing docs/reduce-duplicate-field-types (dc4a1f4) with main (f4b240a)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 11 untouched
⏩ 98 skipped1

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 2, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2896   +/-   ##
=======================================
  Coverage   99.37%   99.37%           
=======================================
  Files          92       92           
  Lines       16196    16198    +2     
  Branches     1915     1915           
=======================================
+ Hits        16095    16097    +2     
  Misses         52       52           
  Partials       49       49           
Flag Coverage Δ
unittests 99.37% <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.

@koxudaxi koxudaxi merged commit a834e62 into main Jan 2, 2026
37 checks passed
@koxudaxi koxudaxi deleted the docs/reduce-duplicate-field-types branch January 2, 2026 14:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 2, 2026

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR only adds documentation and tests for an existing feature (--use-type-alias). It does not modify any source code, CLI options, default behaviors, code generation logic, or templates. The changes consist of: (1) documentation updates explaining how to use --use-type-alias with $defs and $ref to reduce duplicate field types, (2) new test data files, and (3) a new test case. Since no functional changes were made to the codebase, there are no breaking changes.


This analysis was performed by Claude Code Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 2, 2026

🎉 Released in 0.52.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

Labels

breaking-change-analyzed documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants