官檔地址:
個人整理:
1、開啓項目文檔:屬性-生成-XML文檔文件,debug和release都要配置,成功後.csproj文件中會出現
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>ProjectName.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>ProjectName.xml</DocumentationFile>
</PropertyGroup>
2、Nuget安裝 Swashbuckle.AspNetCore
3、Startup.ConfigureServices中添加
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("doc", new Info() { Title = "doc" });
options.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "ProjectName.xml"));
});
4、Startup.Configure中添加
app.UseSwagger();
app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/doc/swagger.json", null));
5、訪問地址:/swagger/index.html