Wrong Xml example data generation
See original GitHub issueHi all, i have a problem with auto-generated Xml example value on Swagger-UI, the xml structure is invalid and can’t be used to test api
Steps to reproduce the problem:
- Create a new Web Api 2 project using VS2015. New -> Project -> Asp.Net Web Application -> WebApi
- Add a class with collection like this
public class Foo
{
public string Name { get; set; }
public int Code { get; set; }
public IList<FooItem> Items { get; set; }
}
public class FooItem
{
public string ItemName { get; set; }
public int ItemCode { get; set; }
}
- Modify the controller ValuesController.cs
public void Post([FromBody]IList<Foo> list)
{
}
- Now look the Xml sample data generated by standard api help page of asp.net web api projeject
<ArrayOfFoo xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SwashbuckleXml.Models">
<Foo>
<Code>2</Code>
<Items>
<FooItem>
<ItemCode>2</ItemCode>
<ItemName>sample string 1</ItemName>
</FooItem>
<FooItem>
<ItemCode>2</ItemCode>
<ItemName>sample string 1</ItemName>
</FooItem>
</Items>
<Name>sample string 1</Name>
</Foo>
<Foo>
<Code>2</Code>
<Items>
<FooItem>
<ItemCode>2</ItemCode>
<ItemName>sample string 1</ItemName>
</FooItem>
<FooItem>
<ItemCode>2</ItemCode>
<ItemName>sample string 1</ItemName>
</FooItem>
</Items>
<Name>sample string 1</Name>
</Foo>
</ArrayOfFoo>
and the Xml sample data generated from Swagger UI
<?xml version="1.0"?>
<Foo>
<Name>string</Name>
<Code>1</Code>
<Items>
<ItemName>string</ItemName>
<ItemCode>1</ItemCode>
</Items>
</Foo>
- As you can see the Xml generated from swagger don’t has Foo root collection and FooItem element
- You can’t use the auto-generated xml sample data on swagger UI, the format is not valid
Any suggestions?
Thanks in advance, Diego
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (5 by maintainers)
Top Results From Across the Web
Wrong Xml example data generation · Issue #1050
Hi all, i have a problem with auto-generated Xml example value on Swagger-UI, the xml structure is invalid and can't be used to...
Read more >Xml Sample Generator - Wrong output?
I am trying to generate a sample xml from a given xsd at runtime. For this purpose I am using the XML Sample...
Read more >Invalid xml data generator
I want to generate problematic data (single space, invalid item, etc.). It could be done by mutation of valid xml, or by generating...
Read more >XML generate exceptions
The following table shows the exception codes that can occur during XML generation. The exception codes are returned in special register XML-CODE ....
Read more >XML Data Generation Failed Error (Doc ID 1907190.1)
Changing the Date Format on Template Causes Sending Process Failed: XML Data Generation Failed Error (Doc ID 1907190.1).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@joegithub @GeorgyOkov Finally I got it working with Xml. Following is the
CustomXmlSchemaFilter
that handles return of collection, collection property in POCO.Specify to use this Schema filter in Swagger via following:
Hope this helps.
The solution above doesn’t work for an return of type string[] or IEnumerable<string>, unless you add also name for items which are not reference: