Classes Added Using GenerateSchema Appear in the Swagger UI But Not in swagger.json
Hello there
I have an Asp.Net Core C# back end project containing controllers and web api methods. Swagger is used to test the web api methods, and to generate swagger.json - we are generating class definitions for the front end to use using nswag studio, based on swagger.json.
I need to add explicitly add some additional class definition to swagger.json. These are for classes which do not appear in any web api endpoints, but which we send to our front end using SignalR.
I have added the additional class definitions using GenerateSchema(). These additional class definitions appear in the Swagger UI (https://localhost:7103/swagger/index.html), but do not appear in swagger.json, for reasons which are unclear. I get the same results when using RegisterType().
Any help on being able to include these definitions in swagger.json would be greatly appreciated.
The code is as follows:
services.AddSwaggerGen(options =>
{
...
options.DocumentFilter<AdditionalSchemasDocumentFilter>();
...
});
public class AdditionalSchemasDocumentFilter : IDocumentFilter
{
...
context.SchemaGenerator.GenerateSchema(typeof(Notification), context.SchemaRepository);
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint($"/swagger/v1/swagger.json", "BackOffice API");
...
});
I have resolved this issue, as per my post at https://docs.microsoft.com/en-us/answers/questions/925357/classes-added-using-generateschema-appear-in-the-s.html