コード例 #1
0
        private static void BuildPaths <TBusiness>(Service service, IList <string> hiddenTags, List <string> visibleTags, IList <Type> definitionsTypesList)
        {
            var type = typeof(TBusiness);

            service.Paths = new List <Path>();

            var da = type.GetCustomAttribute <SwaggerWcfAttribute>();

            if (da == null || hiddenTags.Any(ht => ht == type.Name))
            {
                return;
            }

            var mapper = new Mapper(hiddenTags, visibleTags);

            if (string.IsNullOrWhiteSpace(service.BasePath))
            {
                service.BasePath = da.ServicePath;
            }

            if (service.BasePath.EndsWith("/"))
            {
                service.BasePath = service.BasePath.Substring(0, service.BasePath.Length - 1);
            }

            var paths = mapper.FindMethods(type, definitionsTypesList);

            service.Paths.AddRange(paths);
        }
コード例 #2
0
        private static void BuildPaths(Service service, IList <string> hiddenTags, IList <Type> definitionsTypesList)
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            service.Paths = new List <Path>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable <TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    SwaggerWcfAttribute da = ti.GetCustomAttribute <SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                    {
                        continue;
                    }

                    Mapper mapper = new Mapper(hiddenTags);

                    IEnumerable <Path> paths = mapper.FindMethods(da.ServicePath, ti.AsType(), definitionsTypesList);
                    service.Paths.AddRange(paths);
                }
            }
        }
コード例 #3
0
        private static void BuildPaths(Service service, IList <string> hiddenTags, List <string> visibleTags, IList <Type> definitionsTypesList)
        {
            service.Paths = new List <Path>();

            var types = GetAssemblyTypes(hiddenTags);
            var useBasePathProperty = types.Select(t => t.GetCustomAttribute <SwaggerWcfAttribute>().ServicePath)
                                      .Distinct()
                                      .Count() == 1;

            foreach (var ti in types)
            {
                var da = ti.GetCustomAttribute <SwaggerWcfAttribute>();

                if (service.Info is null)
                {
                    service.Info = ti.GetServiceInfo();
                }

                var mapper = new Mapper(hiddenTags, visibleTags);

                if (string.IsNullOrWhiteSpace(service.BasePath) && useBasePathProperty)
                {
                    service.BasePath = da.ServicePath;
                }

                if (service.BasePath != null && service.BasePath.EndsWith("/"))
                {
                    service.BasePath = service.BasePath.Substring(0, service.BasePath.Length - 1);
                }

                string basePath = null;
                if (!useBasePathProperty)
                {
                    basePath = da.ServicePath;

                    if (basePath != null && basePath.EndsWith("/"))
                    {
                        basePath = basePath.Substring(0, basePath.Length - 1);
                    }
                    if (basePath != null && basePath.StartsWith("/") == false)
                    {
                        basePath = "/" + basePath;
                    }
                }

                var paths = mapper.FindMethods(ti.AsType(), definitionsTypesList, basePath);
                service.Paths.AddRange(paths);
            }
        }
コード例 #4
0
        private static Dictionary <TypeInfo, ServiceBuildInfo> BuildPaths(IList <string> hiddenTags)
        {
            var wcfAssembly = typeof(ServiceContractAttribute).Assembly.GetName().Name;

            // if assembly is from GAC, then we don't need to process it
            // or if assembly doesn't reference System.ServiceModel so it can't have WCF services and we also can safely ignore it
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
                                    .Where(
                assembly =>
                !assembly.GlobalAssemblyCache ||
                assembly.GetReferencedAssemblies().Any(a => a.Name != wcfAssembly)).ToArray();

            Dictionary <TypeInfo, ServiceBuildInfo> result = new Dictionary <TypeInfo, ServiceBuildInfo>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable <TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    SwaggerWcfAttribute da = ti.GetCustomAttribute <SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                    {
                        continue;
                    }

                    Mapper mapper = new Mapper(hiddenTags);

                    var info = new ServiceBuildInfo();
                    info.DefinitionsTypesList = new List <Type>();
                    info.Name  = da.Name;
                    info.Paths = mapper.FindMethods(da.ServicePath, ti.AsType(), info.DefinitionsTypesList).ToList();

                    result.Add(ti, info);
                }
            }

            return(result);
        }
コード例 #5
0
ファイル: ServiceBuilder.cs プロジェクト: JFDionne/swaggerwcf
        private static void BuildPaths(Service service, IList <string> hiddenTags, List <string> visibleTags, IList <Type> definitionsTypesList)
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            service.Paths = new List <Path>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable <TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    SwaggerWcfAttribute da = ti.GetCustomAttribute <SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                    {
                        continue;
                    }

                    if (service.Info is null)
                    {
                        service.Info = ti.GetServiceInfo();
                    }

                    Mapper mapper = new Mapper(hiddenTags, visibleTags);

                    if (string.IsNullOrWhiteSpace(service.BasePath))
                    {
                        service.BasePath = da.ServicePath;
                    }

                    if (service.BasePath.EndsWith("/"))
                    {
                        service.BasePath = service.BasePath.Substring(0, service.BasePath.Length - 1);
                    }

                    IEnumerable <Path> paths = mapper.FindMethods(ti.AsType(), definitionsTypesList);
                    service.Paths.AddRange(paths);
                }
            }
        }
コード例 #6
0
ファイル: ServiceBuilder.cs プロジェクト: poulad/swaggerwcf
        private static void BuildPaths <TBusiness>(SwaggerSchema service, IList <string> hiddenTags, List <string> visibleTags, IList <Type> definitionsTypesList)
        {
            Type type = typeof(TBusiness);

            service.Paths = new Dictionary <string, PathItem>();

            SwaggerWcfAttribute da = type.GetCustomAttribute <SwaggerWcfAttribute>();

            if (da == null || hiddenTags.Any(ht => ht == type.Name))
            {
                return;
            }

            Mapper mapper = new Mapper(hiddenTags, visibleTags);

            IEnumerable <Path> paths = mapper.FindMethods(da.BasePath, type, definitionsTypesList);
            //service.Paths.AddRange(paths);
        }
コード例 #7
0
ファイル: ServiceBuilder.cs プロジェクト: Robin--/swaggerwcf
        private static void BuildPaths(Service service, IList<string> hiddenTags, IList<Type> definitionsTypesList)
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            service.Paths = new List<Path>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable<TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    var da = ti.GetCustomAttribute<SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                        continue;

                    var mapper = new Mapper(hiddenTags);

                    IEnumerable<Path> paths = mapper.FindMethods(da.ServicePath, ti.AsType(), definitionsTypesList);
                    service.Paths.AddRange(paths);
                }
            }
        }