You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: cross-enum conflict detection is order-dependent due to GetValues() returning prefixed names #2391
GenerateEnums prefixes enum constant names when two enums share a value (e.g. "running" in both instance-state and volume-state becomes InstanceStateRunning / VolumeStateRunning). The conflict check calls e1.GetValues(), which returns already-prefixed names for enums marked in an earlier iteration. Those prefixed names no longer match the raw values of later enums, so some conflicts are missed and affected enums stay unprefixed.
Whether an enum gets prefixed ends up depending on iteration order rather than actual value overlap.
Minimal reproduction: three string enums where A shares "running" with B and "migrating" with C. A and B are compared first and both get marked. When A is later compared with C, A.GetValues() returns ["AStateRunning", "AStateMigrating"], neither of which matches C's raw value "Migrating", so C stays unprefixed.
Fix: compare Schema.EnumValues keys instead of GetValues() output. EnumValues always holds unprefixed identifiers regardless of whether the enum has been marked yet. PR: #2390
// Now, go through all the enums, and figure out if we have conflicts with
). In the range over enums when a collision is detected, then the loop sets e1.PrefixTypeName = true (also for e2) and puts them back into the array enums. However, this has an effect on a third enum that would collide as EnumDefinition.GetValues() (see
) uses that PrefixTypeName right away and the collision will no longer be detected.
A solution would be to first loop over all enums and just note down which ones collide. In a second step, their PrefixTypeName is then set to true. But @natalie-o-perret 's solution seems more spot-on.
And then as a (potential) remedy (for one case) as a help for others stumbling over this issue: In our code base this popped up because kin-openapi inlined enum definitions in the swagger.json instead of using $ref. See the bug getkin/kin-openapi#1158 in kin-openapi.
This caused a lot more conflicts to show up (because of enum definitions inline multiple times) and thus the conflict resolution kicking in (with the bug making it flaky as described in the issue here).
In our case, we updated from 0.134.0 to 0.140.0 and the additionally inlined enum definitions were removed and the issue/flakiness on our code was solved.
Can confirm; multiple endpoints sharing an inline enum value set this latent landmine for us. When we went to add a new enum, the generated client changes were way larger than expected, and it turned out to be that the names of all of those enum constants just "happened" to come out to what they did based on this bug. We are biting the one time bullet and moving to 2.8.0 and accepting the breaking change.
Activity
frederikheber-freiheit commentedon Jun 5, 2026
I have just stumbled upon the same bug in our code base: Here's a minimum working example.
Depending on the order of
enums, this will generatewhile we expect
The issues results from
GenerateEnums()in pkg/codegen/codegen.go (seeoapi-codegen/pkg/codegen/codegen.go
Line 1022 in c32c9d9
enumswhen a collision is detected, then the loop setse1.PrefixTypeName = true(also fore2) and puts them back into the arrayenums. However, this has an effect on a third enum that would collide asEnumDefinition.GetValues()(seeoapi-codegen/pkg/codegen/schema.go
Line 217 in c32c9d9
PrefixTypeNameright away and the collision will no longer be detected.A solution would be to first loop over all enums and just note down which ones collide. In a second step, their
PrefixTypeNameis then set to true. But @natalie-o-perret 's solution seems more spot-on.frederikheber-freiheit commentedon Jun 5, 2026
And then as a (potential) remedy (for one case) as a help for others stumbling over this issue: In our code base this popped up because kin-openapi inlined enum definitions in the swagger.json instead of using $ref. See the bug getkin/kin-openapi#1158 in kin-openapi.
This caused a lot more conflicts to show up (because of enum definitions inline multiple times) and thus the conflict resolution kicking in (with the bug making it flaky as described in the issue here).
In our case, we updated from 0.134.0 to 0.140.0 and the additionally inlined enum definitions were removed and the issue/flakiness on our code was solved.
tcarpenter-eqix commentedon Oct 8, 2026
Can confirm; multiple endpoints sharing an inline enum value set this latent landmine for us. When we went to add a new enum, the generated client changes were way larger than expected, and it turned out to be that the names of all of those enum constants just "happened" to come out to what they did based on this bug. We are biting the one time bullet and moving to 2.8.0 and accepting the breaking change.