OpenAPITools / OpenAPITools/openapi-generator

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

Open
#18,987 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring server generator and its enumPropertyNaming handling, comparing the Kotlin server behavior described in the issue. Trace generated enum handling for request parameters and request bodies, then verify that the original casing is preserved consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.