zoukankan      html  css  js  c++  java
  • swagger的配置

      // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1",
                        new Info
                        {
                            Title = "API接口文档",
                            Version = "v1",
                            Description = "开发接口调试.",
                            Contact = new Contact
                            {
                                Name = "ListXiong",
                                Email = "",
                            },
                            TermsOfService = "None"
                        }
                     );
                     //注释
                    c.IncludeXmlComments(GetXmlCommentsPath());
                });
    
                services.AddSupportServices();
              
            }
    
            // 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();
                }
               
                app.UseMvc();
                app.UseSwagger(c =>
                {
                    c.RouteTemplate = "doc/{documentName}/swagger.json";
                });
                app.UseSwaggerUI(c =>
                {
                    c.RoutePrefix = "doc";
                    c.SwaggerEndpoint("/doc/v1/swagger.json", "API v1");
                });
                app.UseStaticFiles();
            }
            /// <summary>
            /// 获取XML文档地址
            /// </summary>
            /// <returns></returns>
            private string GetXmlCommentsPath()
            {
                var app = PlatformServices.Default.Application;
                return Path.Combine(app.ApplicationBasePath, Path.ChangeExtension(app.ApplicationName, "xml"));
            }            
  • 相关阅读:
    15、线程
    17、lambda表达式
    16、sockect
    14、反射(reflect)
    13、集合2
    java 基本类型、包装类、字符串之间的转换
    13、集合1
    12、NIO、AIO、BIO二
    12、NIO、AIO、BIO一
    11、流与文件
  • 原文地址:https://www.cnblogs.com/AnAng/p/9203782.html
Copyright © 2011-2022 走看看