Skip to content
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] 2.3.0 enum support can lead to collisions #7300

Closed
grokify opened this issue Jan 3, 2018 · 5 comments
Closed

[Go] 2.3.0 enum support can lead to collisions #7300

grokify opened this issue Jan 3, 2018 · 5 comments

Comments

@grokify
Copy link

grokify commented Jan 3, 2018

Description

When building a client with enums, it is possible to run into collisions using Go because the enum names are in the same name space.

Swagger-codegen version

2.3.0 using new enum support.

Swagger declaration file content or url

Collision example Open API 2.0 spec excerpt:

  VbIncludeTypeEnum:
    type: string
    enum:
    - knowledge
    - metadata
    - prediction
    - spotting
    - streams
    - transcript
  VbCallbackTypeEnum:
    type: string
    enum:
    - analytics
    - transcript
    - media

Both of these have an enum value, transcript which gets converted to the same constant TRANSCRIPT in the voicebase package: voicebase.TRANSCRIPT:

File: vb_include_type_enum.go

package voicebase

type VbIncludeTypeEnum string

// List of VbIncludeTypeEnum
const (
	KNOWLEDGE VbIncludeTypeEnum = "knowledge"
	METADATA VbIncludeTypeEnum = "metadata"
	PREDICTION VbIncludeTypeEnum = "prediction"
	SPOTTING VbIncludeTypeEnum = "spotting"
	STREAMS VbIncludeTypeEnum = "streams"
	TRANSCRIPT VbIncludeTypeEnum = "transcript"
)

File: vb_callback_type_enum.go

package voicebase

type VbCallbackTypeEnum string

// List of VbCallbackTypeEnum
const (
	ANALYTICS VbCallbackTypeEnum = "analytics"
	TRANSCRIPT VbCallbackTypeEnum = "transcript"
	MEDIA VbCallbackTypeEnum = "media"
)

Compiling the client results in the following errors:

../../vb_include_type_enum.go:22:33: TRANSCRIPT redeclared in this block
	previous declaration at ../../vb_callback_type_enum.go:18:34
../../vb_task_status_enum.go:17:30: ACCEPTED redeclared in this block
	previous declaration at ../../vb_status_enum.go:17:26
../../vb_task_status_enum.go:18:28: FAILED redeclared in this block
	previous declaration at ../../vb_status_enum.go:18:24
../../vb_task_status_enum.go:25:30: FINISHED redeclared in this block
	previous declaration at ../../vb_status_enum.go:21:26
Command line used for generation

$ java -jar swagger-codegen-cli.jar generate -c swagger_voicebase_config.json -i swagger_voicebase_v3.yaml -l go -o .

Steps to reproduce

Generate the client and import the package.

Related issues/PRs

This is being tracked in the client SDK here:

grokify/go-voicebase-v3#4

Suggest a fix/enhancement

Prefix the constant name using upper case snake case

  • INCLUDE_TYPE_ENUM_TRANSCRIPT
  • CALLBACK_TYPE_ENUM_TRANSCRIPT

or UpperCamelCase:

  • IncludeTypeEnumTranscript
  • CallbackTypeEnumTranscript
@CatTail
Copy link
Contributor

CatTail commented Feb 22, 2019

any progress on this issue? can someone help to take a look? @frantuma

@frantuma
Copy link
Member

frantuma commented Mar 6, 2019

@bvwells @nzqpeace @R2wenD2 @vtsao @kevinmu
noticing your thumbs up on the fix proposal, this has been implemented in #9234 (#9208) by @CatTail , can you provide some feedback at #9234 before it gets merged? thanks!

@frantuma
Copy link
Member

implemented in #9234

@dinfyru
Copy link

dinfyru commented Aug 3, 2019

I have same error

./model_create_postback_task_status.go:16:2: OK redeclared in this block
	previous declaration at ./model_create_invoice_status.go:16:27
./model_create_postback_task_status.go:17:2: INTERNAL_ERROR redeclared in this block
	previous declaration at ./model_create_invoice_status.go:17:39
./model_create_postback_task_status.go:18:2: BAD_CREDENTIALS redeclared in this block
	previous declaration at ./model_create_invoice_status.go:18:40
./model_create_postback_task_stream_status.go:16:2: OK redeclared in this block
	previous declaration at ./model_create_postback_task_status.go:16:32
./model_create_postback_task_stream_status.go:17:2: INTERNAL_ERROR redeclared in this block
	previous declaration at ./model_create_postback_task_status.go:17:44
./model_create_postback_task_stream_status.go:18:2: BAD_CREDENTIALS redeclared in this block
	previous declaration at ./model_create_postback_task_status.go:18:45
./model_create_postback_task_stream_status.go:19:2: BAD_REQUEST redeclared in this block
	previous declaration at ./model_create_postback_task_status.go:19:41
./model_create_wallet_status.go:16:2: OK redeclared in this block
	previous declaration at ./model_create_postback_task_stream_status.go:16:38
./model_create_wallet_status.go:17:2: INTERNAL_ERROR redeclared in this block
	previous declaration at ./model_create_postback_task_stream_status.go:17:50
./model_create_wallet_status.go:18:2: BAD_CREDENTIALS redeclared in this block
	previous declaration at ./model_create_postback_task_stream_status.go:18:51
./model_create_wallet_status.go:18:2: too many errors

@hemanthk76in
Copy link

The issue regressed due to the checkin.
164d45f

Any reason why this is done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants