码迷,mamicode.com
首页 > 其他好文 > 详细

Swagger

时间:2019-01-30 21:45:46      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:lse   core   tle   collect   说明文   color   builder   div   hid   

  1. 添加引用 Swashbuckle.AspNetCore
  2. 配置服务
    技术分享图片
    public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
    
                #region Swagger
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new Info
                    {
                        Version = "v0.1.0",
                        Title = "Blog.Core API",
                        Description = "框架说明文档",
                        TermsOfService = "None",
                        Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "Blog.Core", Email = "Blog.Core@xxx.com", Url = "https://www.jianshu.com/u/94102b59cc2a" }
                    });
                });
    
                #endregion
    
            }
    配置服务
  3. 添加中间件
    技术分享图片
    // 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();
                }
    
                #region Swagger
                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1");
                });
                #endregion
    
                app.UseMvc();
            }
    添加中间件
  4. F5运行调试。在域名后面输入 /swagger   (如果要自动打开 swagger, 在lanchSettings.json 中配置 launchUrl )
    技术分享图片
    {
      "$schema": "http://json.schemastore.org/launchsettings.json",
      "iisSettings": {
        "windowsAuthentication": false, 
        "anonymousAuthentication": true, 
        "iisExpress": {
          "applicationUrl": "http://localhost:55159",
          "sslPort": 0
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "swagger",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "ProjectManager.Api": {
          "commandName": "Project",
          "launchBrowser": true,
          "launchUrl": "swagger",
          "applicationUrl": "http://localhost:5000",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        }
      }
    }
    lanchSettings.json

Swagger

标签:lse   core   tle   collect   说明文   color   builder   div   hid   

原文地址:https://www.cnblogs.com/Ken-Cai/p/10339806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!