I\'m using Swashbuckle with ASP.net core. It is producing a nice website with a list of models at the bottom.
How can I add a model to this list that isn\'t al
I've had the same problem, where my models did not show up in swagger, because the return types of my functions had abstract type. I've modified the answer above, so that I could dump everything from a namespace into the model list.
In Startup I define this function:
public class GenericAPI_DocumentFilter : IDocumentFilter where T : class
{
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
foreach (var t in Assembly.GetExecutingAssembly().GetTypes())
{
if (t.Namespace.Contains("MyAPI") && t.IsClass)
{
var a = t.GetCustomAttribute(typeof(DataContractAttribute));
if (a != null)
{
context.SchemaRegistry.GetOrRegister(t);
}
}
}
}
}
In the swagger initialization I add one line:
services.AddSwaggerGen(opt =>
{
...
opt.DocumentFilter>();
...
}