-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Go] Duplicate constant names for enums with same values #535
Comments
Good post @moser4035. I've run into this in the past as well. I've filed PR #542 against the This only changes |
This also happens when the values are similar but have different non-punctuation characters: Here is some test output: type EnumClassAntiCollision string
// List of EnumClassAntiCollision
const (
ABC EnumClassAntiCollision = "abc"
ABC EnumClassAntiCollision = "_abc"
ABC EnumClassAntiCollision = "-abc"
ABC EnumClassAntiCollision = "(abc)"
)
type EnumClass string
const (
// EnumClassAbc captures enum value "_abc"
EnumClassAbc EnumClass = "_abc"
// EnumClassMinusEfg captures enum value "-efg"
EnumClassMinusEfg EnumClass = "-efg"
// EnumClassNrXyz captures enum value "(xyz)"
EnumClassNrXyz EnumClass = "(xyz)"
) |
Hi, I have encountered the same problem in generating go-server stub code. go/model_outer_enum_default_value.go:16:33: PLACED redeclared in this block 1537 OuterEnum: 1550 OuterEnumDefaultValue: Problem still exist? |
I am using version 4.1.1 and I still see the same issue. |
I ran into this with 4.3.2 but see the option for enumClassPrefix which is disabled by default.
fixed it for me |
This problem is supposed to be solved by the |
…e-versions-4.x fix(deps): update dependency compare-versions to v4
No, I disagree. The handling of duplicated enums name isn't finish.
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}} so that if we have:
It will generate: (
ANIMALS_DOG = "dog"
ANIMALS_SHEEP = "sheep"
ANIMALS_BIRD = "bird"
) and (
PETSACCEPTED_DOG = "dog"
PETSACCEPTED_CAT = "cat"
) That many developers, I think, would like to avoid, because it's heavy to use and not required for 3 enums name on 4 that aren't duplicated. → currently I encounter the problem at work: 15 enums names are duplicated among 1,000 and I don't want to prefix 985 enums names that don't require it. And if I my mind, when (
ANIMALS_DOG = "dog"
SHEEP = "sheep"
BIRD = "bird"
) and (
PETSACCEPTED_DOG = "dog"
CAT = "cat"
) |
Description
I've defined enums that contain same values (see below)
The openapi-generator creates constants with the same names.
But this is not allowed and the code does not compile anymore.
I get an error like this:
used openapi-generator version: 3.0.3
OpenAPI declaration file content or url
Generated Go code
file model_color_space.go:
file model_color_primaries.go:
Command line used for generation
java -jar /opt/openapi-generator-cli.jar generate -g go -i openapi.json -o /go/src/go-client
Suggest a fix/enhancement
Maybe this could be solved by adding a prefix to the constants of the enum
The text was updated successfully, but these errors were encountered: