swagger-api / swagger-api/swagger-codegen
[JAVA] JAXB annotations missing for JAVA enums
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When you add xml namespace in swagger for enum, the generated class doesnt get annotated with @XmlRootElement and @XmlAccessorType
Swagger-codegen version
latest version (3.0.22)
Swagger declaration file content or url
jurisdiction:
xml:
namespace: 'http://example.com/schema/1'
type: string
"enum": [
"VIC",
"NSW"
]
Steps to reproduce
Create a swagger definition with an enum as provided in the code sample.
Generate a Java client using the maven plugin or the CLI
Observe that the Java enum classe generated do not have JAXB annotations
Related issues/PRs
Suggest a fix/enhancement
The problem seems to be caused by the enumOuterclass.mustache not having {{>xmlAnnotation}} as the pojo.mustache.
swagger-codegen/modules/swagger-codegen/src/main/resources/JavaSpring/enumOuterClass.mustache
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaSpring/enumOuterClass.mustache
This issue can be resolved by adding the following to enumOuterClass.
In the import section
{{#withXml}}
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
{{/withXml}}
And before public enum declaration
{{>xmlAnnotation}}
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 modules/swagger-codegen/src/main/resources/JavaSpring/enumOuterClass.mustache and compare it with the pojo.mustache template's XML annotation handling. Reproduce the output using the supplied enum definition with the Maven plugin or CLI. Done means generated Java enum classes include the expected JAXB/XML annotations when an XML namespace is specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100