OpenAPITools / OpenAPITools/openapi-generator

[REQ] Support modelPropertyNaming on Spring/Java

Open
#21,190 0 comments 0 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.

Property names on models are (mostly) camelCased when using Spring openapi-generator and there is no way to configure and change this behavior.
I understand the usual need of conforming to Java Beans convention, but on my case we don't need the conformity and would like to have the property names on models to be of the original names on the spec file.
This helps in reducing code and use less reflection (get the original name from Schema annotation of the field) by just using the same naming conventions.

e.g.)
Spec

components:
  schemas:
    FooReq:
      type: object
      properties:
        Name:
          type: string
          description: ABC
        ABC:
          type: integer
          description: Unicode full-width alphabet name

Generated model (Current behavior)

private String name;
private Integer abc;

public String getName() { ... };
public void setName(String name) { ... };

public Integer getAbc() { ... };
public void setAbc(Integer abc) { ... };

Generated model (Desired behavior)

private String Name;
private Integer ABC;

public String getName() { ... };
public void setName(String Name) { ... };

public Integer getABC() { ... };
public void setABC(Integer ABC) { ... };

Describe the solution you'd like

Add an option to keep the original property names from spec for Spring generators.

Describe alternatives you've considered

Option A

Generate file that contains all property names, and add one-to-one entry as nameMappings.

Option B

Extend SpringCodeGen and override toVarName etc methods and publish as library.

Additional context

Other generators (scala, typescript) have modelPropertyNaming that can be set to original as configurable option that does this.

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 by comparing how modelPropertyNaming is handled in the Spring generator with the existing Scala and TypeScript generator options. Trace the Spring model-generation entry points and determine where property names are transformed; the work is done when an original setting preserves the spec property names in generated Spring models, including the examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, tooling
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.