简体   繁体   中英

Classes Added Using GenerateSchema Appear in the Swagger UI But Not in swagger.json

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");
    ..
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM