Пример #1
0
 private static List <string> GetVisibleTags(SwaggerWcfSection config)
 {
     return(config.Tags?.OfType <TagElement>()
            .Where(t => t.Visibile.Equals(true))
            .Select(t => t.Name)
            .ToList() ?? new List <string>());
 }
Пример #2
0
        private static List <Service> BuildService()
        {
            const string      sectionName = "swaggerwcf";
            SwaggerWcfSection config      =
                (SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

            List <string> hiddenTags  = GetHiddenTags(config);
            List <string> visibleTags = GetVisibleTags(config);
            IReadOnlyDictionary <string, string> settings = GetSettings(config);

            var serviceInfos = BuildPaths(hiddenTags);
            var result       = new List <Service>();

            foreach (var serviceInfo in serviceInfos)
            {
                var service = new Service();

                ProcessSettings(service, settings);
                service.Paths       = serviceInfo.Value.Paths;
                service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags,
                                                                 serviceInfo.Value.DefinitionsTypesList);
                service.Name = serviceInfo.Value.Name ?? string.Empty;

                result.Add(service);
            }

            return(result);
        }
Пример #3
0
 private static List <string> GetHiddenTags(SwaggerWcfSection config)
 {
     return(config.Tags == null
                ? new List <string>()
                : config.Tags.OfType <TagElement>()
            .Where(t => t.Visibile.Equals(false))
            .Select(t => t.Name)
            .ToList());
 }
Пример #4
0
        private static Service BuildService()
        {
            const string      sectionName = "swaggerwcf";
            SwaggerWcfSection config      =
                (SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());
            List <Type>   definitionsTypesList = new List <Type>();
            Service       service    = new Service();
            List <string> hiddenTags = GetHiddenTags(config);
            IReadOnlyDictionary <string, string> settings = GetSettings(config);

            ProcessSettings(service, settings);

            BuildPaths(service, hiddenTags, definitionsTypesList);

            service.Definitions = DefinitionsBuilder.Process(hiddenTags, definitionsTypesList);

            return(service);
        }
Пример #5
0
        private static SwaggerSchema BuildServiceCommon(string path, Action <SwaggerSchema, IList <string>, List <string>, IList <Type> > buildPaths)
        {
            const string      sectionName = "swaggerwcf";
            SwaggerWcfSection config      =
                (SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

            List <Type>   definitionsTypesList = new List <Type>();
            SwaggerSchema service     = new SwaggerSchema();
            List <string> hiddenTags  = SwaggerWcfEndpoint.FilterHiddenTags(path, GetHiddenTags(config));
            List <string> visibleTags = SwaggerWcfEndpoint.FilterVisibleTags(path, GetVisibleTags(config));
            IReadOnlyDictionary <string, string> settings = GetSettings(config);

            ProcessSettings(service, settings);

            buildPaths(service, hiddenTags, visibleTags, definitionsTypesList);

            service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

            return(service);
        }
Пример #6
0
        private static Service BuildServiceCommon(string path, Action <Service, IList <string>, List <TagElement>, IList <Type> > buildPaths)
        {
            const string      sectionName = "swaggerwcf";
            SwaggerWcfSection config      =
                (SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

            List <Type> definitionsTypesList = new List <Type>();
            Service     service     = new Service();
            var         hiddenTags  = GetHiddenTags(config);
            var         visibleTags = GetVisibleTags(config);
            IReadOnlyDictionary <string, string> settings = GetSettings(config);

            ProcessSettings(service, settings);

            buildPaths(service, hiddenTags, visibleTags, definitionsTypesList);

            service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

            var distinctTags = service.Paths.SelectMany(p => p.Actions).SelectMany(act => act.Tags)
                               .Distinct();


            var tagsToOrder = distinctTags.Select(tagName =>
            {
                // If tag listed as visible, try to take Description and SortOrder from there
                var existingVisibleDef = visibleTags.FirstOrDefault(vt => vt.Name == tagName);
                return(new TagDeffinition
                {
                    Name = tagName,
                    Description = existingVisibleDef?.Description ?? string.Empty,
                    SortOrder = existingVisibleDef?.SortOrder ?? 0
                });
            });

            service.Tags = tagsToOrder.OrderBy(t => t.SortOrder)
                           .ThenBy(t => t.Name)
                           .ToList();

            return(service);
        }
Пример #7
0
 private static IReadOnlyDictionary <string, string> GetSettings(SwaggerWcfSection config)
 {
     return(config.Settings == null
                ? new Dictionary <string, string>()
                : config.Settings.OfType <SettingElement>().ToDictionary(se => se.Name, se => se.Value));
 }
Пример #8
0
 private static List <TagElement> GetVisibleTags(SwaggerWcfSection config)
 {
     return(config.Tags?.OfType <TagElement>()
            .Where(t => t.Visibile)
            .ToList());
 }