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

[REQ][Java][Server][Spring] Add support for enumPropertyNaming config option in spring server generator #18987

Open
adamzzza opened this issue Jun 20, 2024 · 3 comments

Comments

@adamzzza
Copy link

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

The enumPropertyNaming config option is not supported by the Spring server generator, and all enum properties are generated in upper-case. Having an enum with lower-case properties in the API definition causes the following problem:

  • In GET requests, the client has to send enum values in upper-case because the server uses Enum.valueOf(String) to create an enum instance from request parameters. The valueOf method expects enum values in upper-case.
  • In POST requests, the client has to send enum values in lower-case because the server uses a generated fromValue method to create an enum instance from the request body. The fromValue method expects enum values in lower-case.

Describe the solution you'd like

Implementation of the enumPropertyNaming option and setting it to the value 'original' (as in the Kotlin server) would resolve this problem. The generator would generate all enum properties as defined, without changing them to upper-case.

Additional context

The workaround for this problem is to implement a custom type converter for the enum, which uses the generated fromValue method instead of the enum's valueOf. This converter will be used instead of the default converter for request parameters. However, this is only a workaround for the problem.

@wing328
Copy link
Member

wing328 commented Jun 20, 2024

have you tried using enumNameMappings option to see if it meets your requirement?

https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

@adamzzza
Copy link
Author

have you tried using enumNameMappings option to see if it meets your requirement?

https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

I know that option, but it is also a kind of workaround. I need a resolution for the future, so when a new developer adds another enum, he won't have a problem with it. I had a situation where two developers got stuck on that problem.

@asjp1970
Copy link

asjp1970 commented Jul 12, 2024

Same issue found and all the alternatives I bumped into seem to me workarounds affecting maintainability:

  • First, our input file is a spec from a standard that we should not manipulate. If we use any of x-enum-varnames or the enumNameMappings options, it will force us to manipulate a yaml file that we should use to generate code as is, with no manipulation.
  • The custom type converter is another workaround, that you are forced to use only for those "unfortunate" cases with controllers involving types where the name of the enum constants and their string values are not the same.

I think the best is to have enumPropertyNaming for java generator, as for several other generators.

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

Successfully merging a pull request may close this issue.

3 participants