Skip to content

[REQ] Support modelPropertyNaming on Spring/Java #21190

Open
@azam

Description

@azam

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions