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"));
            }            
  • 相关阅读:
    leetcode ZigZag conversion(mediium) /java
    leetcode longest palindromic substring (medium) /java
    leetcode longest substring without repeating characters(medium) /java
    leetcode two_sum (easy) /java
    think_in_java_多态
    java复用类知识
    java找不到或无法加载主类
    java程序包不存在
    集合
    列表的增删改查
  • 原文地址:https://www.cnblogs.com/AnAng/p/9203782.html
Copyright © 2011-2022 走看看