-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add original enumPropertyNamingType config for java enum generation #20824
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 original enumPropertyNamingType config for java enum generation #20824
Conversation
Underscore should be in the regex, no? |
It is not relevant in my usecase, but i've seen it in some other issues in other languages. I could not find anything specific in the guides except https://google.github.io/styleguide/javaguide.html#s5.1-identifier-names where underscores are mentioned as allowed but not common (special cases only). https://google.github.io/styleguide/javaguide.html#s5.1-identifier-names does not mention anything about underscores. Shall I remove it? thx |
Sorry maybe I misunderstood your question. Underscore is indeed in the regex in den code, just forgot it in the description. Fixed that. |
in the generators supporting this option, the would that meet your requirement? what exact issue(s) your PR aim to fix? |
Instead of a regex, use this:
|
99b6991
to
61d8ac2
Compare
Improvement done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me.
I am just wondering what your use case is. Why do you need/prefer using the new 'original' setting?
So we can use the standard method |
I wish I would not need this feature, but I am generating clients for apis that already exist and they have some weird (but valid in openapi spec) enum values. With the "original" generation I can use the enum as is, else I would need to define a custom type mapping. |
This part I totally understand.
I think the custom mapping exists already, see
For reference, the What's the benefit of using (I am not against these changes, I just don't really understand the reason yet.) |
@martin-mfg I think my problem comes from when original names get manipulated and a value is added to the enum: This is my api definition:
Generated Enum class is:
I am completely aware that this is way more a real java enum as I would also define it myself. But what i expect when with original naming is:
Since when using this type in any interface again they will not match "Test" != "TEST". Retrieving from API and returning the same type will generate a different API specification. Btw. I am using jaxrs jackson on quarkus. |
If you need the String "Test" instead of "TEST" in your custom code, you can call But given that you're using jaxrs, I guess you want to use jackson and it currently can't handle your enums? Then the preferred way to fix this would be to introduce the annotations |
Hi @martin-mfg , thanks for all that Tips, i am aware of these possible workarounds. Guess i am just lazy and wanted to return the Class as it is generated in my own interfaces. At the moment i am simply working around with a import mapping that works great. Edit: I am using jaxrs-spec generator to keep it a little 3rd party lib agnostic ;) https://gitlab.campusonline.community/community/tuinx/-/blob/main/pom.xml?ref_type=heads#L624 |
clever :)
I see that you basically have the |
@martin-mfg Thank you very much for looking in that in detail. But when I use the generated type the exact thing is happening i mentioned above. The API ist not the same anymore Test !== TEST. But that would be exactly what i would want to achieve with the "original" generation option i suggested in this pull request. With the import Mapping, the real generated Type gets replaced, that is why you see the correct Enum. When the mapping is removed the Enum would be:
Sorry if this is getting out of hand ;) I could totally work with any of the workarounds. |
It seems we're on the same page then. In summary - especially for @wing328 who should be the one making a decision here:
|
Same if I use MapStruct, custom configuration needs to be added. |
Good point! Now I am wondering why there are not more issues and PRs addressing JPA. :D |
New config property "original" for java Enum generation. If setting enumPropertyNaming to "original" and enum values in openapi match regex [A-Za-z0-9_]+ then those exact values will be used as java enum type name.
Attention: This only covers a few use cases mentioned in other issues and might not comply with all java conventions. Please review.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg