swagger-api / swagger-api/swagger-codegen
[JAVA] Bug generating classes using JsonProperty Annotation
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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