I am using Swashbuckle.Swagger to generate a Swagger 2.0 schema for my web
api but the JSON that it generated does not display any polymorphic objects
in the Model and Example Values. In other words the JSON that is generated
only contains base objects but not their subclasses.
I have looked at several posts on using C# and Swagger.IExamplesProvider to
display base objects and their subclasses but I haven't had much luck
getting the subclass objects to show up in Model and Example Values.
I also read somewhere that the creator of Swagger decided not to display
inherited objects on purpose. If this is the case then why does the
response body of my Swagger correctly display parent objects and their
subclasses? The following are classes used in my web api:
public class Company
{
public string Name{get; set;}
public string CEO{get; set;}
public List<Details> Branches{get; set;}
public string ContactInfo{get; set;}
}
public class BranchDetail
{
public string HQ{get; set;}
}
public class CaliBranchDetails : Details
{
public string BranchName{get; set;}
public string Country{get; set;}
public string Manager{get; set;}
public string Contact{get; set;}
}
public class NYBranchDetails : Details
{
public string BranchName{get; set;}
public string Country{get; set;}
public string Manager{get; set;}
public string Contact{get; set;}
}
I would like the generated JSON to look like the following:
{
"Company" : {
"Name" : "Company Name",
"CEO" : "CEO Name",
"Branches" : {
"HQ" : "HQ Name",
"CaliBranchDetails" : {"BranchName" : "Branch Name", "Country" : "Country
Name", "Manager" : "Manager Name", "Contact" : "Branch Contact Info"},
"NYBranchDetails" : {"BranchName" : "Branch Name", "Country" : "Country
Name", "Manager" : "Manager Name", "Contact" : "Branch Contact Info"}
},
"ContactInfo" : "Company Contact Info"
}
}
Currently the JSON string that Swagger generates for me does not show
CaliBranchDetails and NYBranchDetails in the Branches object. Can
Swagger.Example be used to modify my existing Schema to generate the above
JSN string without modifying the structure of any existing class?
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.