swagger-api / swagger-api/swagger-codegen

[JAVA] json is adding property twice for classes starting with two capital letters

Open
#12,355 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We are using the swagger-codegen-cli to generate our classes, however, we noticed a strange case where a property that is referenced to (as object) in another .yaml, gets added twice in our json at serialization..
This is possibly caused by the file having a setter/getter with 2 capitals, eg: getDOfferStatus().

Example response:

"result": {
    "dOfferStatus": {
      "href": "",
      "value": "BOOKABLE"
    }
  "dofferStatus":{
      "href":"",
      "value": "BOOKABLE"
    }
 }
Swagger-codegen version

swagger codegen-cli v3

Swagger declaration file content or url
openapi: 3.0.2

info:
  version: 0.14.00
  title: trip offers
  description: trip offers

paths: {}
components:
 schemas:
    TripOfferSummary:
      description: A set of offers for a given trip from origin to destination
      type: object
      properties:
        dOfferStatus:
          $ref: './otheryaml.openapi.yaml#/components/schemas/DOfferStatus'

Which is defined in the other yaml and gets generated inline as: notice we defined it with two capitals as it's a class.

 DOfferStatus:
      type: object
      properties:
        href:
          type: string
          format: uri
        value:
          type: string
          format: urn
Command line used for generation

classpath = project.configurations["swaggerCodegen"]
mainClass = 'io.swagger.codegen.v3.cli.SwaggerCodegen'
args = [
'generate',
'--lang', spring,
'--input-spec', inputFile,
'--config', configFile,
'--output', 'build'
]

config file:
{
"artifactId":"trip-offers-openapi",
"language":"spring",
"modelPackage":"com.system.trip_offers",
"apiPackage":"com.system.api",
"library":"spring-boot",
"generateSupportingFiles":"false",
"interfaceOnly":"true",
"defaultInterfaces":"false",
"singleContentTypes":"true",
"dateLibrary":"java8-localdatetime",
"importMappings": {
"DOfferStatus":"com.otheryamlpackage.DOfferStatus",
}
}

Steps to reproduce

Generate the classes, and serialize/deserialize them.

Suggest a fix/enhancement

I tried using a class by copy pasting the generated code, and added @JsonProperty("dOfferStatus") to the getters and setters of the Java Class. This immediately resolved the issue.

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 Java model classes generated by the shown swagger-codegen-cli command and the Spring configuration using the DOfferStatus import mapping. Reproduce serialization with the TripOfferSummary and DOfferStatus schemas, then inspect how the generated getDOfferStatus/setDOfferStatus accessors are handled. Done means serialization emits one correctly cased dOfferStatus property and deserialization remains functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
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.