zoukankan      html  css  js  c++  java
  • .net core 安装Swagger

    Install-Package Swashbuckle -Pre

    1.Startup

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
    
        //******************* swagger start ***********************
        services.AddSwaggerGen(c =>
        {
            c.SingleApiVersion(new Info
            {
                Version = "v1",     // 这个属性必须要填,否则会引发一个异常
                Title = "Feature List",
                Description = "特征"
            });
        });
    
        services.ConfigureSwaggerGen(c =>
        {
            // 配置生成的 xml 注释文档路径
            c.IncludeXmlComments(GetXmlCommentsPath());
        });
    
        //******************* swagger end ***********************
    }
    
    private string GetXmlCommentsPath()
    {
        var app = PlatformServices.Default.Application;
        return Path.Combine(app.ApplicationBasePath, Path.ChangeExtension(app.ApplicationName, "xml"));
    }
    
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();
    
        app.UseMvc();
    
        //******************* swagger start ***********************
        app.UseSwagger();
        app.UseSwaggerUi("swagger/ui/index");
        //******************* swagger end ***********************
    }
    

    如上:
    //******************* swagger start ***********************
    //******************* swagger end ***********************

    2.launchSettings.json

    {
      "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
          "applicationUrl": "http://localhost:40675/",
          "sslPort": 0
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "swagger/ui/index",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "SigmalHex.WebApi": {
          "commandName": "Project",
          "launchBrowser": true,
          "launchUrl": "swagger/ui/index",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          },
          "applicationUrl": "http://localhost:40676"
        }
      }
    }
    
    

    如:
    "launchUrl": "swagger/ui/index",

  • 相关阅读:
    《Java架构师的第一性原理》24Java基础之并发第5篇Java并发编程的艺术
    《Java架构师的第一性原理》71场景题之搜索引擎ElasticSearch
    70道HR常问面试题,找工作避坑必看
    《Java架构师的第一性原理》10计算机基础之计算机组成原理
    《Java架构师的第一性原理》00计算机的第一性原理
    photoshop--历史记录画笔工具-- 所画之处恢复原图像
    photoshop--去色--彩色图像变成灰度图像
    photoshop--历史记录
    qt5-循环遍历语句foreach
    qt5串口通信
  • 原文地址:https://www.cnblogs.com/pengzhen/p/6909857.html
Copyright © 2011-2022 走看看