ASP.NET CORE NSwag的Swagger

时间:2020-08-31 23:24:48   收藏:0   阅读:80

使用NSwag.AspNetCore启用swagger:微软官网介绍的入门方法

NSwag 提供了下列功能:

借助 NSwag,无需使用现有 API。也就是说,可使用包含 Swagger 的第三方 API,并生成客户端实现。 使用 NSwag,可以加快开发周期,并轻松适应 API 更改。

 

   在 Startup.ConfigureServices 方法中,注册所需的 Swagger 服务:

public void ConfigureServices(IServiceCollection services)
 {
    services.AddSwaggerDocument();
    //swagger
    services.AddControllers();
 }

在 Startup.Configure 方法中,启用中间件为生成的 Swagger 规范和 Swagger UI 提供服务:

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles();

    // Register the Swagger generator and the Swagger UI middlewares
    app.UseOpenApi();
    app.UseSwaggerUi3();

    app.UseMvc();
}

启动应用。 转到:

 

 

 

原文:https://www.cnblogs.com/smileZeng/p/13593608.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!