swagger-api / swagger-api/swagger-codegen

[JAVA] Bug generating classes using JsonProperty Annotation

Open
#12,094 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

I have used the swagger-codegen-maven-plugin to generate model classes from a yaml file.
In this yaml there are a couple of properties that are not camelCase but lowercase with hyphens:

responseElements:

type: object

properties:

x-amz-request-id:

type: string

x-amz-id-2:

type: string

The generated classes get the JsonProperty annotation using these properties, so far so good.

When I create a class and use the proper setters and getters to fill the fields something strange happens, the json from this object contains both the fieldnames and the JsonProperties:

        "responseElements": {
            "xamzRequestId": "xAmzRequestId",
            "xamzId2": "xAmzId2",
            "x-amz-request-id": "xAmzRequestId",
            "x-amz-id-2": "xAmzId2"
        },

How do I get rid of the first 2 elements? They are IMO faulty and I cannot use them in my application.

Swagger-codegen version

3.0.41

Swagger declaration file content or url
responseElements:
  
  type: object
  
  properties:
    
    x-amz-request-id:
      
      type: string
    
    x-amz-id-2:
      
      type: string

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 swagger-codegen-maven-plugin Java model-generation path and reproduce the issue using the YAML declaration shown in the report. Inspect the generated model's accessors and JsonProperty annotations, then verify serialization; done means the output contains only the hyphenated property names rather than duplicate Java-derived names.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, 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.