Swagger用于描述 REST API。 它容许计算机和人员了解服务的功能,而无需直接访问实现(源代码、网络访问、文档)。json
Swashbuckle.AspNetCore
将Swagger生成器添加到 Startup.ConfigureServices 方法中的服务集合中:网络
services.AddSwaggerGen();
在 Startup.Configure 方法中,启用中间件为生成的 JSON 文档和 Swagger UI 提供服务:app
app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
<GenerateDocumentationFile>true</GenerateDocumentationFile>
更改services.AddSwaggerGen();代码以下:code
services.AddSwaggerGen((c => { var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }));