Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kobe-dupont-benerail opened this issue Mar 9, 2024 · 0 comments

Comments

@kobe-dupont-benerail
Copy link

kobe-dupont-benerail commented Mar 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant