swagger-api / swagger-api/swagger-codegen

[Java] Getter/Setter naming convention not followed in generated models

Open
#8,282 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Language: java
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When generating a client library (resttemplate), the getters/setters for a field xField are getXField and setXField. As per naming conventions, this is wrong: https://stackoverflow.com/questions/2948083/naming-convention-for-getters-setters-in-java

We found this issue when testing our API - the responses contained "xfield" and "xField" as jackson serializer did not match the field to the getter generated.

Swagger-codegen version

Using swagger codegen 2.3.1.

Swagger declaration file content or url
		  "xField" : {
			"type" : "string"
		  },
Command line used for generation

Using swagger-codegen-maven-plugin. Maven -> Generate sources

Steps to reproduce

Run generate-sources on a specification containing a field name in some object of form "xField" (a single lower case character followed by upper-case). Generated java model contains getXField() when it should be named getxField().

Suggest a fix/enhancement

Enhance whatever code creates getters and setters for fields in the specification.

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

Reproduce the issue with the provided xField specification using the swagger-codegen-maven-plugin and Maven generate-sources. Trace the Java model generation templates or entry point that produces getters and setters, then verify the generated model uses getxField() and setxField() without creating mismatched Jackson properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.