// 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(); } var swaggerOption = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOption)).Bind(swaggerOption); app.UseSwagger(option => { option.RouteTemplate = swaggerOption.JsonRoute; }); app.UseSwaggerUI(option => { option.SwaggerEndpoint(swaggerOption.UIEndpoint, swaggerOption.Description); }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(); }
// 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.UseCors(options => options.AllowAnyOrigin()); var swaggerOption = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOption)).Bind(swaggerOption); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", swaggerOption.Description); }); app.UseHttpsRedirection(); app.UseMvc(); }
// 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(); } var swaggerOption = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOption)).Bind(swaggerOption); //this lines for configure swagger--------------------------------------------------------------------------------------------------- app.UseSwagger(opt => { opt.RouteTemplate = swaggerOption.JsonRoute; }); app.UseSwaggerUI(opt => { opt.SwaggerEndpoint(swaggerOption.UIEndpoint, swaggerOption.Description); }); app.UseHttpsRedirection(); app.UseStaticFiles(); //----------------------------------------------------------------------------------------------------------------------------------- app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); var swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(swaggerOptions)).Bind(swaggerOptions); app.UseSwagger(option => { option.RouteTemplate = swaggerOptions.JsonRout; } ); app.UseSwaggerUI(option => { option.SwaggerEndpoint(swaggerOptions.UIEndPoint, swaggerOptions.Description); }); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static IServiceCollection AddFengGatewaySwagger(this IServiceCollection services, IConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } SwaggerOption option = new SwaggerOption(); configuration.GetSection("Swagger").Bind(option); //services.Configure<SwaggerOption>(configuration.GetSection("Swagger")); services.AddSwaggerGen(c => { c.SwaggerDoc(option.DocName, new Info { Title = option.Title, Version = option.Version }); }); services.AddSingleton <ISwaggerProjectRepository>(imp => { return(new MySqlSwaggerProjectRepository(imp.GetRequiredService <IDbRepository <ProjectInfo> >())); }); return(services); }
public static IApplicationBuilder UseResillienceSwagger(this IApplicationBuilder app) { IConfiguration configuration = app.ApplicationServices.GetService <IConfiguration>(); SwaggerOption swaggerOption = configuration.GetSection("Resillience:Swagger").Get <SwaggerOption>(); bool enabled = swaggerOption.Enabled; if (!enabled) { return(app); } app.UseSwagger().UseSwaggerUI(options => { string title = swaggerOption.Title; int version = swaggerOption.Version; options.SwaggerEndpoint("/swagger/v1/swagger.json", $"{title} V{version}"); options.DefaultModelsExpandDepth(-1); //设置为 - 1 可不显示models options.DocExpansion(DocExpansion.List); //设置为none可折叠所有方法 #region EF生成的sql显示在swagger页面 bool miniProfilerEnabled = swaggerOption.MiniProfiler; if (miniProfilerEnabled) { options.IndexStream = () => new MiniPro().Min(); } #endregion }).UseMiniProfiler(); return(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(new ExceptionHandlerOptions { ExceptionHandler = new JsonExceptionMiddleware(env).Invoke }); //app.UseHsts(); } app.UseCors("AggriPortalPolicy"); app.UseRequestLocalization(); app.UseStaticFiles(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.UseRequestResponseLogging(); SwaggerOption swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOption)).Bind(swaggerOptions); /// Config Swagger. app.UseSwagger(option => { option.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description); }); //app.UseExceptionHandler(); #pragma warning disable MVC1005 // Cannot use UseMvc with Endpoint Routing. app.UseMvc(); #pragma warning restore MVC1005 // Cannot use UseMvc with Endpoint Routing. }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOptions)).Bind(swaggerOptions); app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description); }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// 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 { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseAuthentication(); var swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOption)).Bind(swaggerOptions); app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description); }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(); }
public static IApplicationBuilder UseFengSwagger(this IApplicationBuilder app, IConfiguration configuration) { SwaggerOption option = new SwaggerOption(); configuration.GetSection("Swagger").Bind(option); app.UseFengSwagger(option); return(app); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions { ResponseWriter = async(context, report) => { context.Response.ContentType = "application/json"; var response = new HealthCheckResponse { Status = report.Status.ToString(), Checks = report.Entries.Select(x => new HealthCheckss { Component = x.Key, Status = x.Value.Status.ToString(), Description = x.Value.Description }), Duration = report.TotalDuration }; await context.Response.WriteAsync(JsonConvert.SerializeObject(response)); } }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseResponseCaching(); app.UseAuthentication(); var swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOptions)).Bind(swaggerOptions); //nếu k cần lấy ngay giá trị đc bind, có thể dùng app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndPoint, swaggerOptions.Description); }); app.UseMvc(); }
// 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.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); var swaggerOptions = new SwaggerOption(); Configuration.GetSection(nameof(SwaggerOptions)).Bind(swaggerOptions); app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description); }); app.UseCors(options => options.WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader()); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); }
public static ResillienceBuilder AddResillienceSwagger(this ResillienceBuilder builder, IConfiguration configuration = null) { configuration = (configuration ?? builder.Services.BuildServiceProvider().GetService <IConfiguration>()); IServiceCollection services = builder.Services; SwaggerOption swaggerOption = configuration.GetSection("Resillience:Swagger").Get <SwaggerOption>(); bool enabled = swaggerOption.Enabled; if (!enabled) { return(builder); } #region MiniProfiler services.AddMiniProfiler(options => { options.RouteBasePath = "/profiler"; }).AddEntityFramework(); #endregion string title = swaggerOption.Title; int version = swaggerOption.Version; services.AddSwaggerGen(options => { #region Authorization var security = new OpenApiSecurityScheme { Description = "JWT模式授权,请输入 Bearer {Token} 进行身份验证", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }; options.AddSecurityDefinition("oauth2", security); options.AddSecurityRequirement(new OpenApiSecurityRequirement { { security, new List <string>() } }); options.OperationFilter <AddResponseHeadersFilter>(); options.OperationFilter <AppendAuthorizeToSummaryOperationFilter>(); options.OperationFilter <SecurityRequirementsOperationFilter>(); #endregion #region Info options.SwaggerDoc($"v{version}", new OpenApiInfo() { Title = title, Version = $"{version}" }); Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.xml").ToList().ForEach(file => { options.IncludeXmlComments(file, true); }); #endregion }); return(builder); }
public static IServiceCollection AddFengSwagger(this IServiceCollection services, IConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } SwaggerOption option = new SwaggerOption(); configuration.GetSection("Swagger").Bind(option); //services.Configure<SwaggerOption>(configuration.GetSection("Swagger")); services.AddSwaggerGen(c => { c.SwaggerDoc(option.DocName, new Info { Title = option.Title, Version = option.Version, Description = option.Description, Contact = new Contact { Name = option.ContactName, Email = option.ContactEmail } }); c.OperationFilter <HeadOperationFilter>(); c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, option.XmlFile)); // Swagger验证部分 c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "请输入带有Bearer的Token", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string>() } }); }); services.AddApiVersioning(o => { o.ReportApiVersions = true; o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); }); return(services); }
public static IApplicationBuilder UseFengSwagger(this IApplicationBuilder app, SwaggerOption options) { if (options == null) { throw new ArgumentException("Missing Dependency", nameof(options)); } app.UseSwagger(c => { c.RouteTemplate = "doc/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"/doc/{options.DocName}/swagger.json", $"{options.Title} {options.Version}"); }); return(app); }