Skip to content

gogen: disambiguate colliding enum value names - #1104

Open
dlanov wants to merge 1 commit into
openconfig:masterfrom
dlanov:fix-1083-enum-name-collision
Open

dlanov wants to merge 1 commit into
openconfig:masterfrom
dlanov:fix-1083-enum-name-collision

Conversation

@dlanov

@dlanov dlanov commented Sep 11, 2026

Copy link
Copy Markdown

Summary

Fixes #1083 by making generated Go enum value identifiers unique when distinct YANG values sanitize to the same name, for example SPEED.1 and SPEED-1.

The existing sanitizer behavior is preserved for non-colliding values, avoiding changes to existing generated APIs. Collisions are resolved deterministically using the enum value ordering and the repository's existing genutil.MakeNameUnique helper, with UNSET reserved for the generated zero value.

Default-value generation uses the same collision-aware naming so references remain synchronized with the generated constant definitions, including enum-valued leafrefs.

Testing

  • go test ./gogen/... -count=1
  • go test ./genutil/... -count=1
  • go vet ./gogen/... ./genutil/...
  • git diff --check
  • Regenerated TestSimpleStructs golden fixtures and confirmed zero diff for existing non-colliding schemas

Fixes #1083

Preserve existing generated enum identifiers when they are unique, while
deterministically uniquifying values that sanitize to the same Go name.

Use the same collision-aware naming for enum default references so generated
defaults continue to match their constant definitions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ygot generator: - and . enum values produce duplicate Go constant names

1 participant