chore: use alias_generator on generated models instead of per-field aliases#858
Draft
vdusek wants to merge 1 commit into
Draft
chore: use alias_generator on generated models instead of per-field aliases#858vdusek wants to merge 1 commit into
vdusek wants to merge 1 commit into
Conversation
…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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
I opened a feature request to koxudaxi/datamodel-code-generator#3419 , so let's see. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The codegen postprocess now adds
alias_generator=to_camelto every model'sConfigDictand emits an explicitField(alias=...)only where the camelCase conversion is irregular (all-caps usage keys,gitHubGistUrl,schema, ...). This drops the explicit per-field aliases in_models.pyfrom 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=Truekeeps snake_case input working. The before/after runtime alias contract is byte-identical across all 212 models / 1060 fields, and_typeddicts.py/_literals.pyregenerate unchanged (the camel*Dictsynthesis now derives names viato_camelplus the irregular-alias overrides).datamodel-codegen has no native option for this (its
--no-aliaswould drop the irregular aliases too), so the work lives inscripts/postprocess_generated_models.py.Closes #852