Skip to content

[Go] Duplicate constant names for enums with same values #535

@moser4035

Description

@moser4035
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:

previous declaration at ../go-client/model_color_primaries.go:18:28
../go-client/model_color_space.go:20:26: SMPTE170_M redeclared in this block

used openapi-generator version: 3.0.3

OpenAPI declaration file content or url
ColorSpace:
  title: ColorSpace
  enum:
  - UNSPECIFIED
  - SMPTE170M
  - SMPTE240M

ColorPrimaries:
  title: ColorPrimaries
  enum:
  - UNSPECIFIED
  - SMPTE170M
  - SMPTE240M
Generated Go code

file model_color_space.go:

        type ColorSpace string

        const (
	        UNSPECIFIED ColorSpace = "UNSPECIFIED"
	        SMPTE170_M ColorSpace = "SMPTE170M"
	        SMPTE240_M ColorSpace = "SMPTE240M"
        )

file model_color_primaries.go:

        type ColorPrimaries string

        const (
	        UNSPECIFIED ColorPrimaries = "UNSPECIFIED"
	        SMPTE170_M ColorPrimaries = "SMPTE170M"
	        SMPTE240_M ColorPrimaries = "SMPTE240M"
        )
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions