OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.38k stars 6.47k forks source link

[BUG][Go] enum name collision #3518

Closed kraney closed 5 years ago

kraney commented 5 years ago
Description

In the generated Go client, specific values of enums are declared at package scope using only the value name. This causes name collisions between enums with overlapping value names.

openapi-generator version

4.1.0-SNAPSHOT

OpenAPI declaration file content or url
components:
  schemas:
    monitor_action_type:
      enum:
      - TRAP
      - SYSLOG
      type: string
    csr_use:
      enum:
      - TLS
      - SYSLOG
      type: string

This results in two package-level variables both named "SYSLOG" causing build failure.

Command line used for generation
docker run --name oas --rm openapitools/openapi-generator-cli:latest generate -g go -i openapi.yaml
Steps to reproduce

Generate code for a schema with the two models above, and try to build it.

Suggest a fix

Possibly prefix the enum value name with the enum type name, e.g. CsrUse_SYSLOG.

auto-labeler[bot] commented 5 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.