public static SwaggerEnabledConfiguration EnableSwaggerUiWithCollectorTheme(this SwaggerEnabledConfiguration configuration, string routeTemplate, Action <SwaggerUiConfig> configure = null) { configuration.EnableSwaggerUi(routeTemplate, config => { configure?.Invoke(config); config.EnableCollectorTheme(); }); return(configuration); }
public void EnableSwaggerUi_NullApiKeyScheme() { var httpConfig = new HttpConfiguration(); var config = new SwaggerDocsConfig(); config.ApiKey("test", "1", ""); var s = new SwaggerEnabledConfiguration(httpConfig, config, ""); Assert.DoesNotThrow(() => s.EnableSwaggerUi("test", c => { })); }
private static void EnableSwaggerUi(SwaggerEnabledConfiguration swaggerEnabledConfiguration) { swaggerEnabledConfiguration.EnableSwaggerUi(swaggerUiConfiguration => { // Use the "DocumentTitle" option to change the Document title. // Very helpful when you have multiple Swagger pages open, to tell them apart. // swaggerUiConfiguration.DocumentTitle("Application Insights Connector"); // Use the "InjectStylesheet" option to enrich the UI with one or more additional CSS stylesheets. // The file must be included in your project as an "Embedded Resource", and then the resource's // "Logical Name" is passed to the method as shown below. // //c.InjectStylesheet(containingAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testStyles1.css"); // Use the "InjectJavaScript" option to invoke one or more custom JavaScripts after the swagger-ui // has loaded. The file must be included in your project as an "Embedded Resource", and then the resource's // "Logical Name" is passed to the method as shown above. // //c.InjectJavaScript(thisAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript1.js"); // The swagger-ui renders boolean data types as a dropdown. By default, it provides "true" and "false" // strings as the possible choices. You can use this option to change these to something else, // for example 0 and 1. // //c.BooleanValues(new[] { "0", "1" }); // By default, swagger-ui will validate specs against swagger.io's online validator and display the result // in a badge at the bottom of the page. Use these options to set a different validator URL or to disable the // feature entirely. //c.SetValidatorUrl("http://localhost/validator"); //c.DisableValidator(); // Use this option to control how the Operation listing is displayed. // It can be set to "None" (default), "List" (shows operations for each resource), // or "Full" (fully expanded: shows operations and their details). // //c.DocExpansion(DocExpansion.List); // Specify which HTTP operations will have the 'Try it out!' option. An empty paramter list disables // it for all operations. // //c.SupportedSubmitMethods("GET", "HEAD"); // Use the CustomAsset option to provide your own version of assets used in the swagger-ui. // It's typically used to instruct Swashbuckle to return your version instead of the default // when a request is made for "index.html". As with all custom content, the file must be included // in your project as an "Embedded Resource", and then the resource's "Logical Name" is passed to // the method as shown below. // //c.CustomAsset("index", containingAssembly, "YourWebApiProject.SwaggerExtensions.index.html"); // If your API has multiple versions and you've applied the MultipleApiVersions setting // as described above, you can also enable a select box in the swagger-ui, that displays // a discovery URL for each version. This provides a convenient way for users to browse documentation // for different API versions. // //c.EnableDiscoveryUrlSelector(); // If your API supports the OAuth2 Implicit flow, and you've described it correctly, according to // the Swagger 2.0 specification, you can enable UI support as shown below. // //c.EnableOAuth2Support( // clientId: "test-client-id", // clientSecret: null, // realm: "test-realm", // appName: "Swagger UI" // //additionalQueryStringParams: new Dictionary<string, string>() { { "foo", "bar" } } //); // If your API supports ApiKey, you can override the default values. // "apiKeyIn" can either be "query" or "header" // if (_isSharedAccessKeyEnabled) { swaggerUiConfiguration.EnableApiKeySupport(_sharedAccessKeyHeaderName, "header"); } }); }
public static void Register(HttpConfiguration config) { var swaggerEnabledConfig = new SwaggerEnabledConfiguration(config, SwaggerDocsConfig.DefaultRootUrlResolver, new[] { "?format=json" }); // Empty string causes "undefined" to appear swaggerEnabledConfig.EnableSwaggerUi(); }
public static void ConfigureApp(IAppBuilder appBuilder) { // Configure Web API for self-host. var config = new HttpConfiguration(); // Configure format var jsonFormatter = new JsonMediaTypeFormatter(); jsonFormatter.SerializerSettings.Formatting = Formatting.Indented; jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.Clear(); config.Formatters.Insert(0, jsonFormatter); config.MapHttpAttributeRoutes(); // SAS Authentication var factory = new AdminStoreFactory(); var store = factory.GetStore(); config.Properties[SASAuthorizeAttribute.ConfigurationPropertyKey] = new SASAuthorizeAttribute.GetKeysAsyncFunc( async(accountName, keyNames) => await store.GetKeysAsync(accountName, keyNames)); config.Properties[SASAuthorizeAttribute.AuthenticationFailureHandlerKey] = new SASAuthorizeAttribute.OnAuthenticationFailed( async(exception, request) => { var account = RequestHelper.ParseAccount(request); var subscriptionId = await RequestHelper.GetSubscriptionId(account); MetricManager.Instance.LogRequestFailed4xx(1, account, subscriptionId, string.Empty); }); config.Services.Replace(typeof(IExceptionHandler), new CustomExceptionHandler()); config.MessageHandlers.Add(new ApiTrackHandler()); // Certificate Authentication config.Properties[CertificateBasedAuthorizeAttribute.ValidClientCertificateKey] = new Func <X509Certificate2, bool>( (cert) => CertificateHelper.ValidClientCertificate(cert)); config.Properties[CertificateBasedAuthorizeAttribute.AuthenticationFailureHandlerKey] = new Action <Exception>( (exception) => MetricManager.Instance.LogRequestFailed4xx(1, "Acis", "Acis", string.Empty)); // Temp for ibiza extension var exposeHeaders = new List <string> { Constants.OperationTrackingIdHeader, ContinuationToken.ContinuationTokenKey }; var cors = new EnableCorsAttribute("*", "*", "*", string.Join(",", exposeHeaders)); config.EnableCors(cors); // Publish static content var physicalFileSystem = new PhysicalFileSystem(@"./StaticContent"); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem, }; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; appBuilder.UseFileServer(options); // Enable Swagger UI var swaggerEnabledConfig = new SwaggerEnabledConfiguration(config, SwaggerDocsConfig.DefaultRootUrlResolver, new[] { "Swagger/2018-10-01.json" }); swaggerEnabledConfig.EnableSwaggerUi(); // TLS1.2+: Enable Connection Logging appBuilder.Use <ConnectionLogMiddleware>("Microsoft.Azure.EngagementFabric.RequestListener"); appBuilder.UseWebApi(config); config.EnsureInitialized(); }