Skip to content

chore: use alias_generator on generated models instead of per-field aliases#858

Draft
vdusek wants to merge 1 commit into
masterfrom
chore/alias-generator-models
Draft

chore: use alias_generator on generated models instead of per-field aliases#858
vdusek wants to merge 1 commit into
masterfrom
chore/alias-generator-models

Conversation

@vdusek

@vdusek vdusek commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The codegen postprocess now adds alias_generator=to_camel to every model's ConfigDict and emits an explicit Field(alias=...) only where the camelCase conversion is irregular (all-caps usage keys, gitHubGistUrl, schema, ...). This drops the explicit per-field aliases in _models.py from 623 to 45 and shrinks the file from 3852 to 3077 lines.

The wire format is unchanged, guarded by tests: Pydantic lets an explicit alias override the generator, and populate_by_name=True keeps snake_case input working. The before/after runtime alias contract is byte-identical across all 212 models / 1060 fields, and _typeddicts.py / _literals.py regenerate unchanged (the camel *Dict synthesis now derives names via to_camel plus the irregular-alias overrides).

datamodel-codegen has no native option for this (its --no-alias would drop the irregular aliases too), so the work lives in scripts/postprocess_generated_models.py.

Closes #852

…liases

Drive the codegen postprocess to put alias_generator=to_camel on each model
and emit explicit Field aliases only for irregular conversions, shrinking the
generated _models.py. The wire format is unchanged.
@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Jun 16, 2026
@vdusek vdusek self-assigned this Jun 16, 2026
@github-actions github-actions Bot added this to the 143rd sprint - Tooling team milestone Jun 16, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Jun 16, 2026
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.51%. Comparing base (6eb267d) to head (98de0c5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #858   +/-   ##
=======================================
  Coverage   94.51%   94.51%           
=======================================
  Files          48       48           
  Lines        5069     5070    +1     
=======================================
+ Hits         4791     4792    +1     
  Misses        278      278           
Flag Coverage Δ
integration 92.93% <ø> (+<0.01%) ⬆️
unit 83.27% <ø> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek

vdusek commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

I opened a feature request to koxudaxi/datamodel-code-generator#3419 , so let's see.

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

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use alias_generator=to_camel on generated Pydantic models instead of per-field aliases

2 participants