Repository navigation
fix(codegen)!: name each generated enum value once - #1799
Conversation
|
Ladon cannot review this PR until merge conflicts are resolved. |
datamodel-code-generator merges an anyOf arm's narrower enum into the root enum without deduplicating, so postal_country_system.System carried zip = 'zip' and zip_1 = 'zip' (19 enums on 10.0.0b4; #1782). Python makes the second member an alias of the first, so nothing broke at runtime, but __members__, autocomplete and member.name offered names that are not AdCP values. post_generate_fixes.dedupe_enum_member_values keeps the first member for each value and removes the repeats (44 members across 11 modules on 3.3.0-beta.3). tests/test_generated_enums_have_no_aliases.py holds the whole generated tree to one member per value. BREAKING CHANGE: the _1 alias members of generated enums (System.zip_1, Field17.ad_request_url_1, ...) are removed. Use the real member (System.zip); System("zip") and member.value are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
f7d34b1 to
ca6c8bd
Compare
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean, tightly-scoped codegen fix.
The PR adds a post-generate pass dedupe_enum_member_values that drops the <name>_1 alias enum members datamodel-code-generator emits when an anyOf arm repeats an enum value. The implementation is AST-based, first-declared-member-wins, uses reverse-order deletion, and ships with idempotence and whole-tree regression tests.
Semver signal is correct: shipped as fix(codegen)!: with a BREAKING CHANGE footer and a migration row. The change is Python-surface-only (.value and System("zip") unchanged), so there is no wire change. The generated domains/** diffs are regeneration output paired with the script + manifest change — the legitimate pathway, not a hand-edit.
No blocking or Medium findings were reported. One non-blocking note: the PR body lists make validate-generated as still running rather than confirmed green; CI is authoritative on whether the committed generated diff reproduces.
Gate check: high_risk false, gated_paths false, no no-auto-approve team match, no prior decision. No findings at any severity — rows 1–8 do not fire, so row 9 applies.
Summary
Closes #1782. datamodel-code-generator merges an
anyOfarm's narrowerenuminto the root enum without deduplicating (postal-country-system.jsonarm 0 narrowssystemto['zip', 'zip_plus_four']), so the generatedStrEnumcarriedzip = 'zip'andzip_1 = 'zip': 19 enums on 10.0.0b4, 44 members across 11 modules on 3.3.0-beta.3.dedupe_enum_member_values: keeps the first member for each value and removes the repeats; registered in the fix list and the effect manifest.tests/test_generated_enums_have_no_aliases.pyholds the whole generated tree to one member per value (the issue's reproduction as a test), pinsSystem.zipdirectly, and unit-tests the pass for idempotence and for leaving non-enum classes alone.MIGRATION_v9_to_v10.mdrow added.BREAKING CHANGE: the _1 alias members of generated enums (System.zip_1, Field17.ad_request_url_1, ...) are removed. Use the real member (System.zip); System("zip") and member.value are unchanged.
Test plan
make lint✓;make validate-generated,make typecheck-alland the CI runner are running locally; CI is authoritative.🤖 Generated with Claude Code