swagger-api / swagger-api/swagger-codegen
Java Code Gen withXML option creates Models with mixed cases for fields
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The Codegen plugin generates the Model classes and adds the @XmlElement tag for the fields but the problem is it creates mixed cases based on object type. If the Swagger field type is String, it creates it with @XmlElement(name = "MixedCase") just like the field name in the Swagger. But for the field type of object, it creates the all small case @XmlElement(name = "smallcase").
It should create the @XmlElement just like its mentioned in Swagger file and should not make it all small case.
For the sample Swagger I posed, it created @XmlElement(name = "flight") as the type is Object.
But for String field CarrierCode, it created @XmlElement(name = "CarrierCode") just like it is in Swagger.
In the end, the Rest API call is failing as the the request is with mixed cases and not per Swagger.
Swagger-codegen version
io.swagger.codegen.v3
swagger-codegen-maven-plugin
3.0.25
Swagger declaration file content or url
"Flight": {
"type": "object",
"properties": {
"carrierCode": {
"type": "string",
"xml": {
"name": "CarrierCode",
"attribute": false,
"wrapped": false
},
"allowEmptyValue": false
},
"noseNumber": {
"type": "string",
"xml": {
"name": "NoseNumber",
"attribute": false,
"wrapped": false
},
"allowEmptyValue": false
}
},
"title": "Flight",
"xml": {
"name": "Flight",
"attribute": false,
"wrapped": false
}
}
Command line used for generation
language-java
withXml-true
Steps to reproduce
Run the Maven Code-Gen plugin for java withXML enabled for a swagger with both Object and String field types.
Related issues/PRs
Suggest a fix/enhancement
Plugin should create the @XmlElement case just like its mentioned in Swagger file and should not make it all small case.
For the sample Swagger I posed, it should create @xmlelement(name = "Flight") just like the Swagger definition.
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 by reproducing the Java generation path with the Maven Codegen plugin, language-java, and withXml=true using the supplied Swagger schema containing String and Object fields. Inspect the generated model annotations and compare the @XmlElement names with the Swagger XML names; done means both field types preserve the declared casing.
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
- 48/100