Skip to content

withXml generated code broken for JavaSpring and Java Resttemplate generators with wrapped collections #5078

@eicki

Description

@eicki
Description

I tried to add xml support for our openapi specs we defined. We use JavaSpring generator for the server and RestTemplate generator for the client.
As a test I tried

animals:
  type: array
  items:
    type: string
    xml:
      name: animal
  xml:
    name: aliens
    wrapped: true

taken from OpenApi 3.0.2 Spec.
Along with the option withXml the generated code is not correct.
For the client (Resttemplate generator) it generates:

  @XmlElement(name = "animal")
  @XmlElementWrapper(name = "aliens")
  private List<String> animals = null;
  @JacksonXmlElementWrapper(useWrapping = true, localName = "animal") 
  public List<String> getAnimals() {
    return animals;
  }

The XmlElement and XmlElementWrapper annotations are correct, but JacksonXmlElementWrapper is not, I would expect

 @JacksonXmlElementWrapper (localName = "aliens")
 @JacksonXmlProperty (localName = "animal")

For the JavaSpring generator it generates

@JacksonXmlProperty(localName = "aliens") // no wrapper annotations at all
private List<String> animals = null;

which is wrong, I expect the same annotations as for the client

 @JacksonXmlElementWrapper (localName = "aliens")
 @JacksonXmlProperty (localName = "animal")

and to be able to choose between technologies, I think you should also include XmlElement and XmlElementWrapper annotations.

openapi-generator version

4.2.2

OpenAPI declaration file content or url
animals:
  type: array
  items:
    type: string
    xml:
      name: animal
  xml:
    name: aliens
    wrapped: true
Command line used for generation

Used openapi-generator-maven-plugin 4.2.2

<generatorName>spring</generatorName>
<library>spring-mvc</library>
<configOptions>
  <dateLibrary>java8</dateLibrary>
  <java8>true</java8>
  <interfaceOnly>true</interfaceOnly>
  <withXml>true</withXml>
</configOptions>

and for the client

<generatorName>java</generatorName>
<library>resttemplate</library>
<configOptions>
  <dateLibrary>java8</dateLibrary>
  <java8>true</java8>
  <withXml>true</withXml>
</configOptions>
Steps to reproduce

Create a yaml spec containing the above model definition taken from the spec

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions