Fix enum member name collisions in generated code#109
Merged
Conversation
The duplicate-name counter appended a numeric suffix but never registered the suffixed name back into the used-name set, so a later value that naturally normalized to the same name (e.g. "Pending2") produced a duplicate member and the generated code failed to compile with CS0102. Probe suffixed candidates against the used-name set and register the chosen name. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes enum-member name deduplication so generated C# no longer emits duplicate members (CS0102) when different enum literals normalize to the same identifier or to an already-suffixed identifier.
Changes:
- Update
SchemaEnumResolver.CreateEnumMembersto probe/allocate a free suffixed member name and register the chosen name to prevent later collisions. - Add a regression test covering one of the previously failing collision sequences.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/OpenApiWeaver.Tests/ClientGeneratorTests.Schemas.cs | Adds a regression test asserting unique generated members for a colliding enum schema. |
| src/OpenApiWeaver/OpenApi/SchemaEnumResolver.cs | Fixes enum member name allocation to avoid emitting colliding identifiers in generated code. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Covers the ordering where the suffixed name is assigned first and a later value naturally normalizes to the same identifier. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Enum member name deduplication could still emit colliding member names, producing generated code that fails to compile with CS0102.
The counter-based dedup in
SchemaEnumResolver.CreateEnumMembersappended a numeric suffix (Pending→Pending2) but never registered the suffixed name back intousedMemberNames. Two collision paths existed:["pending", "Pending", "pending2"]: the second value gets the suffixed namePending2, then the third value naturally normalizes toPending2→ duplicate member.["pending2", "pending", "Pending"]:Pending2is taken naturally first, then the third value's suffix lands on the samePending2→ duplicate member.Changes
EnumSchema_CollidingMemberNames_GeneratesUniqueMembers) that fails against the previous implementation (the test harness compiles the generated source, so the collision surfaced as CS0102).Verification
master, passes with the fix🤖 Generated with Claude Code