예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }