/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="httpConfiguration"></param> /// <param name="configurator"></param> /// <returns></returns> public static SwaggerUiConfig EnableCustomData(this SwaggerUiConfig source, HttpConfiguration httpConfiguration, Action <CustomDataBuilder> configurator) { var configuration = new CustomDataBuilder(); configurator?.Invoke(configuration); const string routeTemplate = "lsl-swaggerui-custom-data"; httpConfiguration.Routes.MapHttpRoute(routeTemplate, routeTemplate, null, null, new CustomDataHandler(configuration)); source.InjectJavaScript(typeof(SwashbuckleExtensions).Assembly, "lsl-swaggerui-custom-data.js"); return(source); }
public void It_should_support_custom_javascript_injection() { var resourceAssembly = typeof(SwaggerConfig).Assembly; _swaggerUiConfig.InjectJavaScript(resourceAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript1.js"); _swaggerUiConfig.InjectJavaScript(resourceAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript2.js"); var index = GetAsString("http://tempuri.org/swagger/ui/index.html"); Assert.IsTrue(index.Contains( "$.getScript('ext/Swashbuckle.Dummy.SwaggerExtensions.testScript1.js');\r\n" + "$.getScript('ext/Swashbuckle.Dummy.SwaggerExtensions.testScript2.js');"), "Custom javascripts not included"); var content = GetAsString("http://tempuri.org/swagger/ui/ext/Swashbuckle.Dummy.SwaggerExtensions.testScript1.js"); Assert.IsTrue(content.StartsWith("var str1"), "custom javascript not served"); content = GetAsString("http://tempuri.org/swagger/ui/ext/Swashbuckle.Dummy.SwaggerExtensions.testScript2.js"); Assert.IsTrue(content.StartsWith("var str2"), "custom javascript not served"); }
public void It_should_support_custom_javascript_injection() { var resourceAssembly = typeof(SwaggerConfig).Assembly; _swaggerUiConfig.InjectJavaScript(resourceAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript1.js"); _swaggerUiConfig.InjectJavaScript(resourceAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript2.js"); var content = GetAsString("http://tempuri.org/swagger/ui/index.html"); StringAssert.Contains( "customScripts: [" + "'Swashbuckle.Dummy.SwaggerExtensions.testScript1.js'," + "'Swashbuckle.Dummy.SwaggerExtensions.testScript2.js'" + "]", content); content = GetAsString("http://tempuri.org/swagger/ui/Swashbuckle.Dummy.SwaggerExtensions.testScript1.js"); StringAssert.StartsWith("var str1", content); content = GetAsString("http://tempuri.org/swagger/ui/Swashbuckle.Dummy.SwaggerExtensions.testScript2.js"); StringAssert.StartsWith("var str2", content); }
/// <summary> /// Use this to enable bearer token in user interface. /// </summary> /// <param name="swaggerUiConfig"> /// The swagger User Interface Config /// </param> public static void EnableBearerToken(this SwaggerUiConfig swaggerUiConfig) => swaggerUiConfig.InjectJavaScript(typeof(SwaggerConfigurationExtensions).Assembly, "Collector.Common.Swagger.Extensions.Resources.clientcredentials.js");