Skip to content

Fix enum member name collisions in generated code#109

Merged
shibayan merged 2 commits into
masterfrom
fix/enum-member-name-collision
Jul 19, 2026
Merged

Fix enum member name collisions in generated code#109
shibayan merged 2 commits into
masterfrom
fix/enum-member-name-collision

Conversation

@shibayan

Copy link
Copy Markdown
Owner

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.CreateEnumMembers appended a numeric suffix (PendingPending2) but never registered the suffixed name back into usedMemberNames. Two collision paths existed:

  • Values ["pending", "Pending", "pending2"]: the second value gets the suffixed name Pending2, then the third value naturally normalizes to Pending2 → duplicate member.
  • Values ["pending2", "pending", "Pending"]: Pending2 is taken naturally first, then the third value's suffix lands on the same Pending2 → duplicate member.

Changes

  • Probe suffixed candidates against the used-name set until a free name is found, and register the final chosen name so later values cannot collide with it.
  • Added a regression test (EnumSchema_CollidingMemberNames_GeneratesUniqueMembers) that fails against the previous implementation (the test harness compiles the generated source, so the collision surfaced as CS0102).

Verification

  • New test fails on master, passes with the fix
  • Full suite: 152/152 passed

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings July 19, 2026 03:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.CreateEnumMembers to 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.

Comment thread tests/OpenApiWeaver.Tests/ClientGeneratorTests.Schemas.cs
@shibayan shibayan self-assigned this Jul 19, 2026
@shibayan shibayan added the bug Something isn't working label Jul 19, 2026
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>
@shibayan
shibayan merged commit 33e85c5 into master Jul 19, 2026
4 checks passed
@shibayan
shibayan deleted the fix/enum-member-name-collision branch July 19, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants