public void It_provides_scheme_host_and_port_from_request_uri() { var request = GetRequestFixtureFor(HttpMethod.Get, "http://tempuri.org:1234"); var rootUrl = SwaggerDocsConfig.DefaultRootUrlResolver(request); Assert.AreEqual("http://tempuri.org:1234", rootUrl); }
public void It_provides_scheme_and_host_but_omits_default_port_from_request_uri(string requestedUri, string expectedUri) { var request = GetRequestFixtureFor(HttpMethod.Get, requestedUri); var rootUrl = SwaggerDocsConfig.DefaultRootUrlResolver(request); Assert.AreEqual(expectedUri, rootUrl); }
private static void EnableSwagger(HttpConfiguration configuration) { configuration .EnableSwagger(c => { c.SingleApiVersion("v1", "Piercer; easily diagnose run-time assemblies and threads"); c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req) + "/api"); c.IncludeXmlComments(GetXmlCommentsPath()); }) .EnableSwaggerUi(); }
public void It_provides_scheme_host_and_port_from_x_forwarded() { var request = GetRequestFixtureFor(HttpMethod.Get, "http://tempuri.org:1234"); request.Headers.Add("X-Forwarded-Proto", "https"); request.Headers.Add("X-Forwarded-Host", "acmecorp.org"); request.Headers.Add("X-Forwarded-Port", "8080"); request.Headers.Add("X-Forwarded-Prefix", "/api"); var rootUrl = SwaggerDocsConfig.DefaultRootUrlResolver(request); Assert.AreEqual("https://acmecorp.org:8080/api", rootUrl); }
public void Configuration(IAppBuilder app) { var container = ContainerConfig.Container; string virtualPath = ConfigurationManager.AppSettings["virtualPathFolderName"] ?? string.Empty; app.Map(new PathString(""), webApiApp => { var webApiConfig = new HttpConfiguration() .ConfigureWebApi(container); webApiApp.Use(async(ctx, next) => { if (ctx.Request.Path.Value == "/") { ctx.Response.Redirect($"{virtualPath}/swagger/ui/index"); return; } await next(); }); webApiConfig .EnableSwagger(c => { c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req) + virtualPath); c.SingleApiVersion("v1", ConfigurationManager.AppSettings.Get("ProductName")); var xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\Documentation.XML"); c.IncludeXmlComments(xmlPath); c.ResolveConflictingActions(x => x.First()); }) .EnableSwaggerUi(c => { c.EnableDiscoveryUrlSelector(); c.InjectJavaScript(typeof(ApiStartupConfig).Assembly, "Api.Setup.SwaggerExtensions.auth.js"); }); webApiApp.UseCors(CorsOptions.AllowAll); webApiApp.UseWebApi(webApiConfig); }); container.Resolve <ILogger>().Info("WebAPI Application started"); }
private void Configure(IAppBuilder app) { _logger.Info("starting web app"); string virtualPath = ""; app.Map(new PathString(""), webApiApp => { _logger.Info($"configuring webApi on {_url}..."); webApiApp.Use(async(ctx, next) => { if (ctx.Request.Path.Value == "/") { ctx.Response.Redirect($"{virtualPath}/swagger/ui/index"); return; } await next(); }); // consider if swagger is required for this setup... _configuration .EnableSwagger(c => { c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req) + virtualPath); c.SingleApiVersion("v1", ConfigurationManager.AppSettings.Get("ProductName")); // Requires setting up persmission for the file access //var xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Documentation.XML"); //c.IncludeXmlComments(xmlPath); c.ResolveConflictingActions(x => x.First()); }) .EnableSwaggerUi(c => { c.EnableDiscoveryUrlSelector(); }); webApiApp.UseWebApi(_configuration); }); _logger.Info("running"); }
public void Configuration(IAppBuilder appBuilder) { appBuilder.Map("/api", api => { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); // Change the API serialization so it does camelCase for // all properties // var jsonFormatter = config.Formatters.JsonFormatter; var settings = jsonFormatter.SerializerSettings; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.EnableSwagger(c => { // Since we mapped the API, we also need to tell Swashbuckle about that // c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req) + "/api"); // Just add a little meta-data to the API // c.SingleApiVersion("v1", "Weather History API"); // Enable the descriptions in by including all the XML comments // c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\bin\WeatherHistory.Web.XML"); }) .EnableSwaggerUi(); api.UseWebApi(config); }); // Add Nancy to the OWIN pipeline at the end so it handles anything // that WebAPI doesn't // appBuilder.UseNancy(); }