[英]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.我有一个包含控制器和 web api 方法的 Asp.Net Core C# 后端项目。 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.
Swagger 用于测试 web api 方法,并生成 swagger.json - 我们正在基于 swagger.json 为前端使用 nswag studio 生成类定义。
I need to add explicitly add some additional class definition to swagger.json.我需要向 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.
这些用于未出现在任何 Web api 端点中的类,但我们使用 SignalR 将其发送到我们的前端。
I have added the additional class definitions using GenerateSchema().我已经使用 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.
这些额外的类定义出现在 Swagger UI (https://localhost:7103/swagger/index.html) 中,但没有出现在 swagger.json 中,原因尚不清楚。 I get the same results when using RegisterType().
使用 RegisterType() 时我得到相同的结果。
Any help on being able to include these definitions in swagger.json would be greatly appreciated.非常感谢能够在 swagger.json 中包含这些定义的任何帮助。
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");
..
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.