-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xml example cannot be generated for response type of array #4650
Comments
Hello @shockey , any ETA on a fix regarding this issue? |
@shockey We're facing issue with XML sample generation in case of collection is part of response object. Kindly let us know about ETA on a fix. |
Added the demo project to reproduce the issue with Swashbuckle for Xml sample generation issue. Demo project |
Any update on this? |
Any workaround solution for this? |
I think this might be related to older issue: Above issue does speak to at least some issue with Swashbuckle OpenAPI generation:
Re. workaround, there is more information in above issue:
Another issue ´seems to be related as well: This has been an issue for a while, but apparently not a priority to fix (I assume collaborators are all using json or don't mind too much about XML examples). |
I'm using NuGet Package Swashbuckle.AspNetCore 5.0.0-rc4 and this is still an Issue on November 12, 2019 |
When you generate the schema for response type 200 for app/ToDoItems/1 we get the following schema for responses: "responses": { When you generate the schema for response type 200 for app/ToDoItems we get the following schema for responses: "responses": { Its this second scenario that is producing the error "XML example cannot be generated; root element name is undefined" in the Swagger UI. |
You can use something like this to wrap
components:
|
Did anyone figure out a workaround for this issue or does this issue still exist? |
This is not working due to some reason. |
Providing any |
Hi all Are there some updates about this? I think I have a similar problem: I have a Spring Boot Rest Api and I want to have the swagger documentation. Mostly the Api produces application/xml. When the return class is annotated with XmlRootElement and the properties have the XmlElement attributes everything is working fine. But if a primitive type or a List is returned, the root element is missing. Is it somehow possible to tell springdoc he should use jaxb to generate all this information/names. So that the xml has the root name and everything which then really gets returned? Thank you very much and best |
I found a work-around for this
I hope this helped! 😉 |
@whateverxforever Thanks for you response :) This would work, yes. But I use springdoc openapi which generates the swagger json file for me. When I annotate my models with @XmlRootElement and @xmlelement the generated schema: xml: is written correctly. For example like this: @XmlRootElement
public class Employee {
@XmlElement
private Address address;
}
@XmlRootElement
public class Address {
} But if the return type of an endpoint is a primitive data type like boolean or a List than the schema: xml: is completely missing. I could add them manually, but the project is quite big. My idea then was if swagger could use jaxb to create this xml informations. Like this, the xml names would be exactly the same as the rest endpoint returns. Do you know more or less what i mean :) |
Hello @Sslimon, I faced the same issue while generating docs using Stoplight for my project. Stoplight was generating the doc fine for JSON data but for XML I had to manually go at each end point and write the code myself. I know it's not what you wanted to hear 😓, but I think this is a common issue in swagger. Sorry couldn't be of any more help. |
Okay, too bad. I was hoping that somebody maybe knows a workaround, but then I can't avoid to adapt it myself :) The JSON is also correct, only the xml stuff is sometime wrong/not complete. But thank you very much for your answers and help! |
I just hit this bug and wow almost 3 years and no fix... |
Same here - Using Swashbuckle 6.1.4 for .NET 5.0.7; I guess no one cares about XML anymore? :) |
Oh my god... I worked many hours for setting up integration between Maven, Jersey, Swagger, Swagger UI... for documenting my WS and now I discover that there is such a big blocking bug, open since 3 years??? |
At least someone understood if the problem is in the swagger.json generated by Swagger Core or in the way that Swagger UI interprets it? Just to find where we could try to create a workaround in the meanwhile... Thanks |
Thanks to these posts:
I solved the problem with this workaround, waiting for the bug to be solved:
I replace it with a block like this:
|
The issue doesn't seem to have a workaround when the XML is just one element with a text node. The goal is
|
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 :
|
Thank you @JeroenHeemskerk, your workaround works and is simpler than mine!
we can correct it inserting this block:
and obtaining this:
|
@bluish5 Thanks for this. I am getting a similar issue when I am using the
Please let me know where to add. |
@Aravinda93, I do not understand your question. The workaround I described is for yaml or json file. |
@JeroenHeemskerk I am developing a RestController application using the When the application gets started the I am not creating the Ref document: https://quarkus.io/guides/openapi-swaggerui |
Hi @Aravinda93, my solution is to edit the generated YAML (or JSON in my case) file, after it has been generated. You save it with a different file name and when user opens Swagger-UI you feed it with your edited file instead of the generated one. |
@borcherspm, I see the XML attribute it is added to the 3.0.0 spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#xml-attribute-prefix-and-namespace but i do not see an annotation for it in the swagger-ui in the https://github.com/eclipse/microprofile-open-api/wiki/Annotation-Samples nor in the code on GitHub. I am affraid there is no annotation for it build yet. There may be a workaround if you make a OASFilter: https://github.com/eclipse/microprofile-open-api/wiki/OASFilter-Samples using a "filterSchema".
|
I made an issue for it microprofile/microprofile-open-api#530 |
@JeroenHeemskerk Thanks a lot for taking the initiative to find the issue and create the issue. I am looking at your provided workaround and trying to achieve something like this. Since it is untested I am getting a few issues. I have created the custom OASFilter and added the same to my project and trying to do something like what you are doing but I am unable to follow certain things. Can you please help me in figuring out the issue? I am unable to follow what exactly I need to check in IF condition and return the schema. Following is the OASFilter that I have created and added the same to my
|
@Aravinda93 someone made the suggestion to use |
4 year as past since today and still no fix? Whats up with this project it's dead or what? |
It's 2023, the pandemic is over but this bug is not? 🤔 |
I was here, and I came here to see if the bug was fixed. 2024 BC |
This may have been fixed in ReDoc: Redocly/redoc#2347 |
Q&A (please complete the following information)
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
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:
Expected behavior
I would expect to see the example xml for the response.
Screenshots
The text was updated successfully, but these errors were encountered: