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.86k stars 6.59k forks source link

[REQ] Add enumClassPrefix option for Go server #6907

Closed mraineri closed 4 years ago

mraineri commented 4 years ago

Is your feature request related to a problem? Please describe.

I'm currently trying to build a Go server from an OpenAPI spec that contains enumerations where some values are re-used in different enumerations. Doing so today, it results in the following errors when building:

$ go build
# github.com/GIT_USER_ID/GIT_REPO_ID/go
go/model_account_service_v1_7_1_account_provider_types.go:19:2: OEM redeclared in this block
    previous declaration at go/model_acceleration_function_v1_0_2_acceleration_function_type.go:23:57
go/model_account_service_v1_7_1_authentication_types.go:19:2: OEM redeclared in this block
    previous declaration at go/model_account_service_v1_7_1_account_provider_types.go:19:47

Describe the solution you'd like

Issue #535 discusses this same problem in the context of Go clients, and others have been able to get around this by using the enumClassPrefix option to add the name of the enumeration to the enum values in order to ensure uniqueness. The Go server option list is limited and does not currently support enumClassPrefix. I would like the same functionality to be made available for Go server code generation.

Describe alternatives you've considered

Changing all enumeration values to ensure uniqueness in the specification itself would be another way around this, but unfortunately the API is shipping at this time and would break compatibility with existing clients.

wing328 commented 4 years ago

@mraineri thanks for the suggestion. I wonder if you've time to file a PR to make the enhancement to the Go server generator.

mraineri commented 4 years ago

Sure, I can take a look at making the enhancement myself and contributing it back.