Skip to content

Guarantee a unique name for the constants that represent enum values #3644

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

Merged
merged 4 commits into from
Aug 19, 2019

Conversation

kraney
Copy link
Contributor

@kraney kraney commented Aug 14, 2019

Proposed fix for #3518

This change adds a prefix to the consts that are defined to represent enum values. This prevents name collisions between different enums having the same value within.

PLACED OuterEnum = "placed"
APPROVED OuterEnum = "approved"
DELIVERED OuterEnum = "delivered"
OuterEnum_PLACED OuterEnum = "placed"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if it's all upper case, e.g. OUTERENUM_PLACED?

Ref: https://stackoverflow.com/a/22688926/677735

We also need an option so that users can stick with the current behavior instead (e.g. PLACED instead of OUTERENUM_PLACED)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the Go guides are pretty adamant about using mixed case, but I elected not to change the part that was already there that didn't. But I can uppercase the typename for consistency.

Unfortunately I doubt I'll dig into the code enough to learn how to add an option flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can help on that.

@wing328
Copy link
Member

wing328 commented Aug 19, 2019

I'll add the option in another PR.

@wing328 wing328 merged commit e086ad1 into OpenAPITools:master Aug 19, 2019
@wing328
Copy link
Member

wing328 commented Aug 19, 2019

Filed #3675

@wing328
Copy link
Member

wing328 commented Aug 19, 2019

#3675 has been merged into master. To enable it, please do --additional-properties enumClassPrefix=true

@wing328
Copy link
Member

wing328 commented Aug 26, 2019

@kraney thanks for the PR, which has been included in the v4.1.1 release: https://twitter.com/oas_generator/status/1165944867391860737

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

Successfully merging this pull request may close these issues.

2 participants