Forum Discussion

rodennis's avatar
rodennis
New Member
6 months ago
Solved

Generating a schema for a generic list in c#

Hello im using swagger in a .NET API project, and trying to generate a schema from a generic list in C#. I have a class with a property of applicants, applicants can have types of applicant, or buisness. When I make the property a type of List<object> swagger ui is presenting value as a string. ex <Applicants>String</Applicants>

 

im trying to achieve something along the lines of the below

<UpdateSfsLoanStatusRequest>
<Applicants>
<Applicant>
</Applicant>
<Business>
</Business>
</Applicants>
</UpdateSfsLoanStatusRequest>

 

below is my class


public class UpdateSfsLoanStatusRequest
{
[XmlArray("Applicants")]
[XmlArrayItem("Applicant", Type=typeof(Applicant))]
[XmlArrayItem("Business", Type=typeof(Business))]
public List<object> Applicants { get; set; }
public class Applicant
{
}
public class Business
{
}
}

 

below is the request body swagger is generating 

<UpdateSfsLoanStatusRequest>
	<Applicants>string</Applicants>
</UpdateSfsLoanStatusRequest>

any help would be much appreciated.

 

Thanks

  • It looks like you want to generate a specific XML structure in Swagger for your .NET API project. Swagger may not infer the desired structure automatically for pc. To achieve the structure you've shown, you can use XML attributes to specify the structure explicitly. Heres how you can modify your class to achieve the desired XML structure:

     

     

1 Reply

  • hammerharshbarg's avatar
    hammerharshbarg
    Occasional Visitor

    It looks like you want to generate a specific XML structure in Swagger for your .NET API project. Swagger may not infer the desired structure automatically for pc. To achieve the structure you've shown, you can use XML attributes to specify the structure explicitly. Heres how you can modify your class to achieve the desired XML structure: