博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VS2017 安装Swagger初步认识
阅读量:5300 次
发布时间:2019-06-14

本文共 3271 字,大约阅读时间需要 10 分钟。

1.安装NuGet包

2.配置

3.运行测试

参考博客:

一 安装NuGet包

包名:Swashbuckle.AspNetCore

二 配置

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.HttpsPolicy;using Microsoft.AspNetCore.Mvc;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using Microsoft.Extensions.Options;using Swashbuckle.AspNetCore.Swagger;namespace WebApplicationCoreAPIStudy4{    public class Startup    {        public Startup(IConfiguration configuration)        {            Configuration = configuration;        }        public IConfiguration Configuration { get; }        // This method gets called by the runtime. Use this method to add services to the container.        public void ConfigureServices(IServiceCollection services)        {            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);            ////注册Swagger生成器,定义一个和多个Swagger 文档            //services.AddSwaggerGen(c =>            //{            //    c.SwaggerDoc("v1", new Info { Title = "My API_info", Version = "v1_info" });            //});            //注册Swagger生成器,定义一个和多个Swagger 文档            services.AddSwaggerGen(c =>            {                c.SwaggerDoc("v1", new Info                {                    Version = "v1",                    Title = "yilezhu's API",                    Description = "A simple example ASP.NET Core Web API",                    TermsOfService = "None",                    Contact = new Contact                    {                        Name = "依乐祝",                        Email = string.Empty,                        Url = "http://www.cnblogs.com/yilezhu/"                    },                    License = new License                    {                        Name = "许可证名字",                        Url = "http://www.cnblogs.com/yilezhu/"                    }                });                // 为 Swagger JSON and UI设置xml文档注释路径                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)                var xmlPath = Path.Combine(basePath, "WebApplicationCoreAPIStudy4.xml");                c.IncludeXmlComments(xmlPath);            });                   }        // 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();            }            else            {                app.UseHsts();            }            app.UseHttpsRedirection();            app.UseMvc();            //启用中间件服务生成Swagger作为JSON终结点            app.UseSwagger();            //启用中间件服务对swagger-ui,指定Swagger JSON终结点            app.UseSwaggerUI(c =>            {                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1_endpoint");                //加上后,访问地址:https://localhost:44389                //c.RoutePrefix = string.Empty;//访问地址:https://localhost:44389/swagger                  });        }    }}

三 运行测试

 

转载于:https://www.cnblogs.com/ligenyun/p/10533729.html

你可能感兴趣的文章
修改linux远程22端口,linux修改ssh远程端口22
查看>>
Linux系统的创始者,组图:Linux之父的办公室首度曝光
查看>>
关于linux的环境变量设置,linux环境变量设置
查看>>
socket模块,简单的套接字,加循环
查看>>
个人主页优化(2)
查看>>
Node 中异常收集与监控
查看>>
二丶Python字符串1
查看>>
七丶Python字典
查看>>
一丶Python简介
查看>>
Excel-信息函数&数组公式
查看>>
Excel-基本操作
查看>>
面对问题,如何去分析?(分析套路)
查看>>
Excel-逻辑函数
查看>>
面对问题,如何去分析?(日报问题)
查看>>
数据分析-业务知识
查看>>
BZOJ1208[HNOI2004]宠物收养场——treap
查看>>
nodejs vs python
查看>>
poj-1410 Intersection
查看>>
艰难中前行
查看>>
[pytorch学习]1.pytorch ubuntu安装
查看>>