private static void ApplyCommonSwaggerConfiguration(SwaggerDocsConfig c, IUnityContainer container, string cacheKey, string[] xmlCommentsFilePaths) { var cacheManager = container.Resolve <ICacheManager <object> >(); c.CustomProvider(defaultProvider => new CachingSwaggerProvider(defaultProvider, cacheManager, cacheKey)); c.MapType <object>(() => new Schema { type = "object" }); c.IgnoreObsoleteProperties(); c.DescribeAllEnumsAsStrings(); c.OperationFilter(() => new OptionalParametersFilter()); c.OperationFilter(() => new FileResponseTypeFilter()); c.OperationFilter(() => new FileUploadOperationFilter()); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); c.RootUrl(message => new Uri(ComputeHostAsSeenByOriginalClient(message), message.GetRequestContext().VirtualPathRoot).ToString()); c.PrettyPrint(); c.ApiKey("apiKey") .Description("API Key Authentication") .Name("api_key") .In("header"); foreach (var path in xmlCommentsFilePaths) { c.IncludeXmlComments(path); } }
private static void ApplyCommonSwaggerConfiguration(SwaggerDocsConfig c, IUnityContainer container, string cacheKey, string[] xmlCommentsFilePaths) { var cacheManager = container.Resolve <ICacheManager <object> >(); c.CustomProvider(defaultProvider => new CachingSwaggerProvider(defaultProvider, cacheManager, cacheKey)); c.MapType <object>(() => new Schema { type = "object" }); c.IgnoreObsoleteProperties(); c.DescribeAllEnumsAsStrings(); c.OperationFilter(() => new OptionalParametersFilter()); c.OperationFilter(() => new FileResponseTypeFilter()); c.OperationFilter(() => new FileUploadOperationFilter()); c.OperationFilter(() => new AssignOAuth2SecurityOperationFilter()); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); c.RootUrl(message => new Uri(ComputeHostAsSeenByOriginalClient(message), message.GetRequestContext().VirtualPathRoot).ToString()); c.PrettyPrint(); c.OAuth2("OAuth2") .Description("OAuth2 Resource Owner Password Grant flow") .Flow("password") .TokenUrl(HttpRuntime.AppDomainAppVirtualPath?.TrimEnd('/') + "/token"); foreach (var path in xmlCommentsFilePaths) { c.IncludeXmlComments(path); } }
private static void EnableSwagger(SwaggerDocsConfig swaggerDocsConfig) { swaggerDocsConfig.SingleApiVersion(AppSettings.ApiVersion, $"{AppSettings.ApplicationName} {AppSettings.ApiVersion}"); swaggerDocsConfig.RootUrl(GetRootUrlFromAppConfig); swaggerDocsConfig.IncludeXmlComments(GetXmlCommentsPath()); swaggerDocsConfig.OperationFilter <SwaggerCorrelationIdHeader>(); swaggerDocsConfig.OperationFilter <FormatXmlCommentProperties>(); swaggerDocsConfig.OperationFilter <SwaggerAuthorizationHeader>(); }
/// <summary> /// Configures Swagger and how it integrates into the Http Server /// </summary> /// <param name="docsConfig"></param> private static void ConfigureSwagger(SwaggerDocsConfig docsConfig) { var assemblyName = Assembly.GetExecutingAssembly().GetName(); docsConfig.SingleApiVersion(assemblyName.Version.ToString().Replace('.', '_'), $"{assemblyName.Name}.API"); docsConfig.IncludeXmlComments(HostingEnvironment.MapPath($"~/bin/{assemblyName.Name}.xml")); docsConfig.UseFullTypeNameInSchemaIds(); // This line is specifically for running this api in a virtual directory // See https://github.com/domaindrivendev/Swashbuckle/issues/305 docsConfig.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/").TrimEnd('/')); }
internal static void Configure(HttpConfiguration config) { var swConfig = new SwaggerDocsConfig(); swConfig.RootUrl(m => GetOwinAppBasePath(m.GetOwinContext())); swConfig.OperationFilter(() => new ODataResponcesOperationFilter()); swConfig.OperationFilter(() => new AddExtendedMetadataOperationFilter()); swConfig.DocumentFilter(() => new ODataRemoveNotAllowedOperationFilter()); swConfig.SingleApiVersion("v2", "BlackCoffeeTalk oData Services"); swConfig.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, swConfig, config) .Configure(odatasw => { odatasw.EnableSwaggerRequestCaching(); odatasw.IncludeNavigationProperties(); })); swConfig.ApiKey("Token") .Description("Filling bearer token.") .Name("Authorization") .In("header"); config.Routes.MapHttpRoute("swagger_docs", "", new { apiVersion = "v2" }, null, new SwaggerDocsHandler(swConfig)); }
private static void ApplyCommonSwaggerConfiguration(SwaggerDocsConfig c, IUnityContainer container, string cacheKey, string[] xmlCommentsFilePaths) { var cacheManager = container.Resolve<ICacheManager<object>>(); c.CustomProvider(defaultProvider => new CachingSwaggerProvider(defaultProvider, cacheManager, cacheKey)); c.MapType<object>(() => new Schema { type = "object" }); c.IgnoreObsoleteProperties(); c.DescribeAllEnumsAsStrings(); c.OperationFilter(() => new OptionalParametersFilter()); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); c.RootUrl(message => new Uri(message.RequestUri, message.GetRequestContext().VirtualPathRoot).ToString()); c.PrettyPrint(); c.ApiKey("apiKey") .Description("API Key Authentication") .Name("api_key") .In("header"); foreach (var path in xmlCommentsFilePaths) { c.IncludeXmlComments(path); } }
public void RootUrl_Test() { var sc = new SwaggerDocsConfig(); Assert.DoesNotThrow(() => sc.RootUrl(null)); }