注册Swagger生成器

            //注册Swagger生成器,定义一个和多个Swagger 文档
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "eric's API",
                    Description = "A simple example ASP.NET Core Web API",
                    TermsOfService = "None",
                    Contact = new Contact
                    {
                        Name = "eric",
                        Email = string.Empty,
                        Url = "http://www.eric.com/"
                    },
                    License = new License
                    {
                        Name = "许可证名字",
                        Url = "http://www.eric.com"
                    }
                });
                // 为 Swagger JSON and UI设置xml文档注释路径
               //获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                var xmlPath = Path.Combine(basePath, "SwaggerDemo.xml");
                c.IncludeXmlComments(xmlPath);
            });

 

 

posted @ 2020-01-07 09:47  Honker书生  阅读(447)  评论(0编辑  收藏  举报