Ejemplo n.º 1
0
        private static void GetXmlCommentsPath(SwaggerDocsConfig config)
        {
            var commentsFile1 = string.Format(@"{1}BIN\{0}.XML", Assembly.GetExecutingAssembly().GetName().Name, AppDomain.CurrentDomain.BaseDirectory);
            var commentsFile2 = string.Format(@"{1}BIN\Pharos.Logic.OMS.XML", Assembly.GetExecutingAssembly().GetName().Name, AppDomain.CurrentDomain.BaseDirectory);

            config.IncludeXmlComments(commentsFile1);
            config.IncludeXmlComments(commentsFile2);
        }
Ejemplo n.º 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.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);
            }
        }
Ejemplo n.º 3
0
        private static void SetXmlCommentsPath(SwaggerDocsConfig config)
        {
            string strBaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
            string strWebXMLPath    = string.Format(@"{0}\App_Data\React_Jwt.XML", strBaseDirectory);

            config.IncludeXmlComments(strWebXMLPath);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        private void SetVersionAndComments(SwaggerDocsConfig config, string version, string title)
        {
            string str = string.Empty;

            try
            {
                config.SingleApiVersion(version, title);
                char[] trimChars = new char[] { '\\' };
                str = AppDomain.CurrentDomain.BaseDirectory.Trim(trimChars);
                string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (directoryName != null)
                {
                    char[] chArray2 = new char[] { '\\' };
                    if (directoryName.Trim(chArray2) != str)
                    {
                        str = Path.Combine(str, "bin");
                    }
                }
            }
            catch { }
            if (!string.IsNullOrEmpty(str))
            {
                foreach (string str3 in Directory.EnumerateFiles(str, "*.XML").ToArray <string>())
                {
                    config.IncludeXmlComments(str3);
                }
            }
        }
Ejemplo n.º 6
0
 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>();
 }
Ejemplo n.º 7
0
 private static void Configure(SwaggerDocsConfig swaggerConf)
 {
     //todo reflection
     swaggerConf.SingleApiVersion("v1", "My Thai Star Email Service");
     //Add swagger documentation
     foreach (var doc in GetXmlDocumentsForSwagger())
     {
         swaggerConf.IncludeXmlComments(GetXmlCommentsPath(doc));
     }
 }
        /// <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('/'));
        }
Ejemplo n.º 9
0
        public static void IncludeXmlFiles(this SwaggerDocsConfig c, params string[] assemblyNames)
        {
            var binFolder = $@"{AppDomain.CurrentDomain.BaseDirectory}\bin\";

            foreach (var assemblyName in assemblyNames)
            {
                var filePath = Path.Combine(binFolder, $"{assemblyName}.xml");

                if (File.Exists(filePath))
                {
                    c.IncludeXmlComments(filePath);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c"></param>
        public static void IncludeXmlComments(SwaggerDocsConfig c)
        {
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var assemblies    = AppDomain.CurrentDomain.GetAssemblies().Where(q => q.FullName.Contains("Com.Web"));

            foreach (var item in assemblies)
            {
                var xmlName = Path.Combine(baseDirectory, string.Concat("bin\\", item.GetName().Name, ".XML"));
                if (File.Exists(xmlName))
                {
                    c.IncludeXmlComments(xmlName);
                }
            }
        }
        public static void IncludeApiComments(
            this SwaggerDocsConfig config, params string[] patterns)
        {
            var files =
                (AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ??
                 AppDomain.CurrentDomain.BaseDirectory).Split(';')
                .SelectMany(path => Directory.GetFiles(path, "*.xml"));

            foreach (var file in files)
            {
                var filename = new FileInfo(file).Name;
                if (patterns.Any(pattern => Regex.IsMatch(filename, pattern)))
                {
                    config.IncludeXmlComments(file);
                }
            }
        }
Ejemplo n.º 12
0
        private static void IncludeApiComments(SwaggerDocsConfig config)
        {
            var files =
                (AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ??
                 AppDomain.CurrentDomain.BaseDirectory).Split(';')
                .SelectMany(path => Directory.GetFiles(path, "*.xml"));

            foreach (var file in files)
            {
                var filename = new FileInfo(file).Name;
                if (filename.IndexOf("Api", StringComparison.OrdinalIgnoreCase) >= 0 ||
                    filename.IndexOf("Improving.AspNet", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    config.IncludeXmlComments(file);
                }
            }
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
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.");
            }
        }
Ejemplo n.º 15
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.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);
            }
        }
Ejemplo n.º 16
0
 private void IncludeXmlComments(SwaggerDocsConfig config)
 {
     config.IncludeXmlComments(String.Format(@"{0}\XmlComments.xml", AppDomain.CurrentDomain.BaseDirectory));
 }
Ejemplo n.º 17
0
        private static void AddXmlcommentsPaths(SwaggerDocsConfig c)
        {
            var baseDir = System.AppDomain.CurrentDomain.BaseDirectory;

            c.IncludeXmlComments(baseDir + "bin\\WeatherForecast.xml");
        }