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

Add a config converter for enums #2678

Closed
dmlloyd opened this issue May 31, 2019 · 5 comments · Fixed by #2927
Closed

Add a config converter for enums #2678

dmlloyd opened this issue May 31, 2019 · 5 comments · Fixed by #2927
Assignees
Labels
kind/enhancement New feature or request
Milestone

Comments

@dmlloyd
Copy link
Member

dmlloyd commented May 31, 2019

Description
Add a converter for enums that would translate between the idiomatic Java enum syntax and the idiomatic skewered-lowercase syntax of configuration. For example:

Java enum constant name Canonical equivalent
DISCARD discard
READ_UNCOMMITTED read-uncommitted
SIGUSR1 sigusr1
TrendBreaker trend-breaker
MAKING_LifeDifficult making-life-difficult
YeOldeJBoss ye-olde-jboss

Hyphens and underscores would be interchangeable on input. Values would be case-insensitive. Note the special exception JBoss is always treated as a whole word (see io.quarkus.deployment.util.StringUtil).

@dmlloyd dmlloyd added the kind/enhancement New feature or request label May 31, 2019
@machi1990
Copy link
Member

Hi @dmlloyd
I was giving this a thought and I have got a question regarding the conversion.
What happens when converting the following values:

  • makingLifeDifficult: is it making-life-difficult?
  • READ__UNCOMMITTED: is it read-committed or read--committed?

@dmlloyd
Copy link
Member Author

dmlloyd commented May 31, 2019

I would say:

  • makingLifeDifficult would be making-life-difficult as you say
  • READ__UNCOMMITTED could go either way (whichever way is easier to specify): such a constant is so poorly named that it probably should be changed. :)

@machi1990
Copy link
Member

@dmlloyd thanks for the clarifications.

So I have given this a thought and gave it a go here

  • Some enums are not / need not to be in skewCase e.g Protocol cf ServerSslConfig.java, I thought of adding an option skewCase for @ConfigItem to opt out the conversion.
  • Some modifications had to be done for ObjectConfigType OptionalObjectConfigType and ObjectListConfigType as I could not find a way to make it by implementing a MP Config Converter. Did you have something similar in mind? Or is there a way to make it simple?

@machi1990 machi1990 self-assigned this Jun 21, 2019
@dmlloyd
Copy link
Member Author

dmlloyd commented Jun 21, 2019

@dmlloyd thanks for the clarifications.

So I have given this a thought and gave it a go here

  • Some enums are not / need not to be in skewCase e.g Protocol cf ServerSslConfig.java, I thought of adding an option skewCase for @ConfigItem to opt out the conversion.

You're right, we do need a way to opt out. Maybe hyphenate-values is a better name? But it only applies to enum properties, so maybe a separate @Hyphenate(false) is better. We could give an error if the @Hyphenate annotation is given on non-enum properties.

  • Some modifications had to be done for ObjectConfigType OptionalObjectConfigType and ObjectListConfigType as I could not find a way to make it by implementing a MP Config Converter. Did you have something similar in mind? Or is there a way to make it simple?

I think your approach is correct, generally speaking.

@machi1990
Copy link
Member

You're right, we do need a way to opt out. Maybe hyphenate-values is a better name? But it only applies to enum properties, so maybe a separate @Hyphenate(false) is better. We could give an error if the @Hyphenate annotation is given on non-enum properties.

Re: skewCase I was not sure about the naming either so I decided to went to the very end of my approach. Finally, I like what you propose better regarding an @Hypenate annotation.
I will go along that line and allow opting in for hypnated-values by @Hyphenate(true). The default value is false.

  • Some modifications had to be done for ObjectConfigType OptionalObjectConfigType and ObjectListConfigType as I could not find a way to make it by implementing a MP Config Converter. Did you have something similar in mind? Or is there a way to make it simple?

I think your approach is correct, generally speaking.

Okay, let me prepare a commit and open a draft PR so that we can continue with the discussion there.

machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 21, 2019
machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 21, 2019
machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 21, 2019
machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 21, 2019
machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 28, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jun 28, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 2, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 3, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 11, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 11, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 12, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
machi1990 added a commit to machi1990/quarkus that referenced this issue Jul 26, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
@gsmet gsmet added this to the 0.20.0 milestone Jul 30, 2019
Dufgui pushed a commit to Dufgui/quarkus that referenced this issue Aug 26, 2019
Adds a default enum converter for hyphenated values to override implicit enum default converter.
Fixes quarkusio#2678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants