.net core中swagger设置参数(折叠、不显示models)

1、使用 NuGet 安装 Swashbuckle.AspNetCore 包

Install-Package Swashbuckle.AspNetCore

2、修改 Startup.cs 文件

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    services.AddSwaggerGen(options =>
    {
        options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
        {
            Version = "v1",
            Title = "My API",
            Description = "by JiaJia"
        });
    });
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseMvc();

     //启用中间件服务生成Swagger作为JSON终结点
            app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; });
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("v1/swagger.json", "ProjectFlowMangement10WebApi API"); c.RoutePrefix = "swagger";
                c.DocExpansion(DocExpansion.None);
                c.DefaultModelsExpandDepth(-1);
            });
}

说明:
1、DocExpansion设置为none可折叠所有方法
2、DefaultModelsExpandDepth设置为-1 可不显示models

你可能感兴趣的:(技术分享)