swagger-ui: xml example cannot be generated for response type of array
Q&A (please complete the following information)
- OS: Windows 10
- Browser: Firefox, Chrome, Edge
- Method of installation: npm
- Swagger-UI version: 3.11.0
- Swagger/OpenAPI version: Swagger 2.0
Content & configuration
I’ve reproduced this locally, but even easier to demonstrate, petstore has the same issue.
Example Swagger/OpenAPI definition: https://generator.swagger.io/api/swagger.json
snippet from swagger.json
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
Describe the bug you’re encountering
In swagger ui, when you have a GET that has a response that is a list, and you selected content type of xml, the Example Value has an error “XML example cannot be generated”.
To reproduce…
Steps to reproduce the behavior:
- Go to https://editor.swagger.io
- Expand /pet/findByStatus
- Make sure Response content type is application/xml
- Example Value for status code 200 has “XML example cannot be generated”
Expected behavior
I would expect to see the example xml for the response.
Screenshots

About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 6
- Comments: 35
I found a work-around for this https://app.swaggerhub.com/apis/whateverxforever/SampleApi/v1-oas3
I hope this helped! 😉
It’s 2023, the pandemic is over but this bug is not? 🤔
4 year as past since today and still no fix?
Whats up with this project it’s dead or what?
I made an issue for it https://github.com/eclipse/microprofile-open-api/issues/530
I found out that if you include an xml name AND wrapped: true it wil generate a correct xml example, and even arrays of string can be controlled how the xml examle is shown for the element tag.
For example in the Pet example code if you add these 3 lines to the response code and/or these 2 lines to the items section in de definitions:
it wil correctly make an example with a root tag <Pets>: