Пример #1
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);
                }
            }
        }
Пример #2
0
        private static void BuildPaths <TBusiness>(Service service, IList <string> hiddenTags, List <string> visibleTags, IList <Type> definitionsTypesList)
        {
            Type type = typeof(TBusiness);

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

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

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

            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(type, definitionsTypesList);

            service.Paths.AddRange(paths);
        }
Пример #3
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);
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        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);
        }