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);
            }
        }
Exemple #2
0
        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>();
 }
        public static void ApplyCqlDefaults(this SwaggerDocsConfig c)
        {
            c.OperationFilter <AddAuthorizationHeaderParameterOperationFilter>();
            c.OperationFilter <SupportFlaggedEnums>();
            c.OperationFilter <HideCancellationToken>();

            c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

            c.DescribeAllEnumsAsStrings();
        }
 public void Apply(SwaggerDocsConfig c)
 {
     foreach (var header in headers)
     {
         c.ApiKey(header.Key).Name(header.Name).Description(header.Description).In("header");
     }
     c.OperationFilter(() => this);
 }
        internal static SwaggerDocsConfig GetDefaultConfigWithTRex()
        {
            SwaggerDocsConfig config = new SwaggerDocsConfig();

            config.SingleApiVersion("v1", "TRexTestApi");
            config.ReleaseTheTRex();
            config.OperationFilter <IncludeParameterNamesInOperationIdFilter>();

            return(config);
        }
Exemple #7
0
        public static void ReleaseTheTRex(this SwaggerDocsConfig config)
        {
            if (config == null)
            {
                return;
            }

            config.SchemaFilter <TRexSchemaFilter>();
            config.OperationFilter <TRexOperationFilter>();
        }
        /// <summary>
        /// Confgures Swaschbuckle to provide additional metadata in methods which use FromQuery attribute so the API provided by DotVVM API generator is easier to use.
        /// </summary>
        public static void EnableDotvvmIntegration(this SwaggerDocsConfig options, Action <DotvvmApiOptions> configureOptions = null)
        {
            var apiOptions = new DotvvmApiOptions();

            configureOptions?.Invoke(apiOptions);

            var propertySerialization = new DefaultPropertySerialization();

            options.OperationFilter(() => new AddAsObjectAnnotationOperationFilter(propertySerialization));
            options.SchemaFilter(() => new AddTypeToModelSchemaFilter());
            options.DocumentFilter(() => new HandleKnownTypesDocumentFilter(apiOptions, propertySerialization));
        }
Exemple #9
0
        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 IncludeXmlCommentsFromBinFolder(SwaggerDocsConfig c)
        {
            var binPath = HostingEnvironment.MapPath("~/bin");

            var xmlCommentsPaths = Directory.GetFiles(binPath, "*.xml");

            if (!xmlCommentsPaths.Any())
            {
                throw new ConfigurationErrorsException("No .xml files were found in the bin folder.");
            }

            foreach (var xmlCommentsPath in xmlCommentsPaths)
            {
                c.IncludeXmlComments(xmlCommentsPath);
            }

            c.OperationFilter(() => new ControllerlessActionOperationFilter(xmlCommentsPaths));
        }
        public static SwaggerDocsConfig UseReflectionDocumentation(this SwaggerDocsConfig source)
        {
            source.OperationFilter(() => ReflectionDocumentationProvider.Default);

            //HACK: This is a hack to get access to the model filters because it isn't public
            //source.ModelFilters<ReflectionDocumentationProvider>();
            var modelFilters = source.GetType().GetField("_modelFilters", BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Instance);
            var filters      = modelFilters?.GetValue(source) as System.Collections.Generic.IList <Func <IModelFilter> >;

            if (filters != null)
            {
                filters.Add(() => ReflectionDocumentationProvider.Default);
            }
            else
            {
                Debug.WriteLine("Unable to get model filters from SwaggerDocsConfig, model documentation will be unavailable.");
            }

            return(source);
        }
Exemple #12
0
        private static void IncludeXmlCommentsFromAppDataFolder(SwaggerDocsConfig c)
        {
            var appDataPath = HostingEnvironment.MapPath("~/App_Data");

            // The XML comment files are copied using a post-build event (see project settings / Build Events).
            string[] xmlCommentsPaths = Directory.GetFiles(appDataPath, "*.xml");

            foreach (string xmlCommentsPath in xmlCommentsPaths)
            {
                c.IncludeXmlComments(xmlCommentsPath);
            }

            var filter = new ControllerlessActionOperationFilter(xmlCommentsPaths);

            c.OperationFilter(() => filter);

            if (!xmlCommentsPaths.Any())
            {
                throw new ConfigurationErrorsException("No .xml files were found in the App_Data folder.");
            }
        }
 public static void EnableAzureAdB2cOAuth2(this SwaggerDocsConfig c, string tenantId, bool useV2Endpoint, string description, params ScopeDescription[] scopes)
 {
     ValidateScopes(scopes.Select(s => s.ScopeName));
     c.OAuth2("oauth2")
     .Description(description)
     .Flow("implicit")
     .AuthorizationUrl(AuthorizationUrl(tenantId, useV2Endpoint))
     //.TokenUrl(TokenUrl(tenantId, useV2Endpoint))
     .Scopes(s =>
     {
         for (int i = 0; i < DefaultScopes.Length; i++)
         {
             s.Add(DefaultScopes[i], DefaultScopesNames[i]);
         }
         foreach (var scopeDescription in scopes)
         {
             s.Add(scopeDescription.ScopeName, scopeDescription.Description);
         }
     });
     c.OperationFilter(() => new AssignOAuth2SecurityRequirements(scopes));
 }
        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);
            }
        }
Exemple #15
0
 public void Apply(SwaggerDocsConfig c)
 {
     c.ApiKey(Key).Name(Name).Description(Description).In("header");
     c.OperationFilter(() => this);
 }
Exemple #16
0
 /// <summary>
 /// Confgures Swaschbuckle to provide additional metadata in methods which use FromQuery attribute so the API provided by DotVVM API generator is easier to use.
 /// </summary>
 public static void EnableDotvvmIntegration(this SwaggerDocsConfig options)
 {
     options.OperationFilter <AddAsObjectAnnotationOperationFilter>();
     options.OperationFilter <HandleGridViewDataSetReturnType>();
 }
Exemple #17
0
 public static void EnablePaging(this SwaggerDocsConfig config)
 {
     config.OperationFilter(() => new PagingOperationFilter());
 }
Exemple #18
0
 public static void EnablePaging(this SwaggerDocsConfig config, string pageAttributeName, string sizeAttributeName)
 {
     config.OperationFilter(() => new PagingOperationFilter(pageAttributeName, sizeAttributeName));
 }
Exemple #19
0
 public static SwaggerDocsConfig ConfigureStardust(this SwaggerDocsConfig swaggerConfig, Action <SwaggerDocsConfig> additionalConfigurations, IServiceProvider serviceProvider)
 {
     swaggerConfig.OperationFilter(() => new StardustOperationDescriptor(serviceProvider));
     return(swaggerConfig);
 }
        private static void AddInternalOperationFilters(SwaggerDocsConfig swaggerDocsConfig)
        {
            Contract.Requires(swaggerDocsConfig != null);

            swaggerDocsConfig.OperationFilter(() => new EnableQueryFilter());
        }
 /// <summary>
 /// Enregistrement du Header
 /// </summary>
 /// <param name="c"></param>
 public void Apply(SwaggerDocsConfig c)
 {
     c.OperationFilter(() => this);
 }