I want to write a RESTful webserver which serves the following XML document:
<Services>
<TileMapService title="TMS server" version="1.0.0" href="/tms/1.0.0"/>
<TileMapService title="TMS server" version="1.0.1" href="/tms/1.0.1"/>
</Services>
I use the OpenAPI Generator Gradle Plugin to generate model classes for my SpringBoot RestController.
openApiGenerate {
generatorName = "spring"
...
configOptions = [
withXml: "true",
...
]
}
with the following openapi.yaml spec file:
...
"paths" : {
"/tms" : {
"get" : {
"operationId" : "getServices",
"responses" : {
"200" : {
"content" : {
"text/xml" : {
"schema" : {
"$ref" : "#/components/schemas/ServicesRoot"
}
}
}
}
}
}
}
},
"components" : {
"schemas" : {
"ServicesRoot" : {
"xml" : {
"name" : "Services"
},
"properties" : {
"TileMapServices" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/TileMapService"
}
}
}
},
"TileMapService" : {
"xml" : {
"name" : "TileMapService"
},
"properties" : {
"title" : {
"type" : "string",
"xml" : {
"attribute" : true
}
},
"version" : {
"type" : "string",
"xml" : {
"attribute" : true
}
},
"href" : {
"type" : "string",
"xml" : {
"attribute" : true
}
}
}
},
...
The generator creates a ServicesRoot model class from this spec. When I use this model with my RestController to create a response I get:
<Services>
<TileMapServices>
<TileMapServices title="TMS server" version="1.0.0" href="/tms/1.0.0"/>
<TileMapServices title="TMS server" version="1.0.1" href="/tms/1.0.1"/>
</TileMapServices>
</Services>
Can you please help me to solve the following problems:
- The
TileMapServicearray items are wrapped inside a<TileMapServices>XML-element. I need the array items "unwrapped" within the</Services>parent XML-element. - The array items XML-Element name is "pluralized" as
<TileMapServices .../>with a trailing "s".
I want to use the generated model class as response object for the RestController and with Jackson XMLMapper to serialize XML documents.
This is what I need:
<Services>
<TileMapService title="TMS server" version="1.0.0" href="/tms/1.0.0"/>
<TileMapService title="TMS server" version="1.0.1" href="/tms/1.0.1"/>
</Services>