Open
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have the following swagger which defined an array of message object.
swagger: "2.0"
definitions:
Status:
type: "object"
properties:
messages:
type: "array"
items:
$ref: "#/definitions/Message"
xml:
name: message
xml:
name: messages
wrapped: true
i want to generate java code which matches the xml below. Note that the message array ( element) wrapped message items and each item are named .
<status>
<messages>
<message>
</message>
<message>
</message>
</messages>
</status>
The problem is in the generation of Status java class which contains the messages list :
public class Status implements Serializable {
@XmlElement(name = "messages") // problem here
@XmlElementWrapper(name = "messages")
private List<Message> messages = null;
}
The value of attribut name in XmlElement annotation should be message (without s). The generator ignores the name tag under items tag in the swagger file.
openapi-generator version
5.1.0
OpenAPI declaration file content or url
I'm not sure if the bug is located in this template file but the following line in pojo.mustache seems strange; The value name uses the same variable 'xmlName' for both @xmlelement and @XmlElementWrapper.
// Is a container wrapped={{isXmlWrapped}}
{{#items}}
// items.name={{name}} items.baseName={{baseName}} items.xmlName={{xmlName}} items.xmlNamespace={{xmlNamespace}}
// items.example={{example}} items.type={{dataType}}
@XmlElement({{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}name = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/items}}
{{#isXmlWrapped}}
@XmlElementWrapper({{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}name = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isXmlWrapped}}