Skip to content

Add support for multiple aliases using Pydantic v2 AliasChoices#2845

Merged
koxudaxi merged 3 commits intomainfrom
feature/multiple-aliases-support
Dec 28, 2025
Merged

Add support for multiple aliases using Pydantic v2 AliasChoices#2845
koxudaxi merged 3 commits intomainfrom
feature/multiple-aliases-support

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

Fixes: #2474

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 28, 2025

Warning

Rate limit exceeded

@koxudaxi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 0 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 19f1fb7 and 3c54f36.

⛔ Files ignored due to path filters (10)
  • tests/data/aliases/discriminator_multiple_aliases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/aliases/discriminator_no_literal.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/aliases/multiple_aliases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/aliases/multiple_aliases_parameters.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/graphql/multiple-aliases.graphql is excluded by !tests/data/**/*.graphql and included by none
  • tests/data/graphql/multiple-aliases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/discriminator_multiple_aliases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/discriminator_no_literal.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/multiple_aliases.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/openapi/multiple_aliases_parameters.yaml is excluded by !tests/data/**/*.yaml and included by none
📒 Files selected for processing (19)
  • src/datamodel_code_generator/__main__.py
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/model/pydantic_v2/base_model.py
  • src/datamodel_code_generator/model/pydantic_v2/imports.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
  • src/datamodel_code_generator/reference.py
  • tests/data/expected/main/graphql/graphql_multiple_aliases_pydantic_v2.py
  • tests/data/expected/main/jsonschema/jsonschema_discriminator_multiple_aliases_pydantic_v2.py
  • tests/data/expected/main/jsonschema/jsonschema_discriminator_no_literal_multiple_aliases_pydantic_v2.py
  • tests/data/expected/main/jsonschema/jsonschema_multiple_aliases_pydantic_v2.py
  • tests/data/expected/main/openapi/openapi_multiple_aliases_parameters_pydantic_v2.py
  • tests/main/graphql/test_main_graphql.py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/openapi/test_main_openapi.py
  • tests/test_resolver.py
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/multiple-aliases-support

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 Dec 28, 2025

📚 Docs Preview: https://pr-2845.datamodel-code-generator.pages.dev

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 28, 2025

CodSpeed Performance Report

Merging #2845 will not alter performance

Comparing feature/multiple-aliases-support (426e715) with main (d0f64f1)

⚠️ 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 Dec 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.50%. Comparing base (bb0eb62) to head (3c54f36).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2845      +/-   ##
==========================================
- Coverage   99.51%   99.50%   -0.02%     
==========================================
  Files          90       90              
  Lines       14258    14479     +221     
  Branches     1695     1735      +40     
==========================================
+ Hits        14189    14407     +218     
  Misses         37       37              
- Partials       32       35       +3     
Flag Coverage Δ
unittests 99.50% <100.00%> (-0.02%) ⬇️

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 a2a4d74 into main Dec 28, 2025
35 of 37 checks passed
@koxudaxi koxudaxi deleted the feature/multiple-aliases-support branch December 28, 2025 19:31
@github-actions
Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR adds support for multiple aliases using Pydantic v2 AliasChoices as an additive feature. Analysis: (1) CLI/API: The --aliases option now accepts both string values (existing) and list of strings (new), which is backward compatible - existing alias files continue to work. (2) Code Generation: Generated code only changes when users explicitly opt-in to the new list format for aliases. Existing single-alias configurations produce identical output. (3) Internal API: While get_valid_field_name_and_alias() return type changed from tuple[str, str | None] to tuple[str, str | list[str] | None], this is an internal method in the parser/resolver. External users who rely only on the documented CLI and Python API are not affected. (4) Templates: No template changes required - the validation_aliases processing happens in Python code, not Jinja2 templates, so custom templates continue to work. (5) The new validation_aliases field on DataModelFieldBase is optional with a None default, maintaining backward compatibility. This is a purely additive feature that requires explicit opt-in via the new alias list format.


This analysis was performed by Claude Code Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 1, 2026

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

Multiple Aliases for Pydantic v2

1 participant