Ejemplo n.º 1
0
        private void GenerateToc(RestTocGroup restTocGroup, GraphAggregateResult aggregateResult)
        {
            foreach (var aggregateOperation in aggregateResult.AggregateOperations)
            {
                if (string.IsNullOrEmpty(aggregateOperation.MainOperation.GroupName))
                {
                    Console.WriteLine($"Should at least have one group for operation: {aggregateOperation.MainOperation.InternalOpeartionId}");
                }

                var groupNames = new List <string>();
                if (aggregateOperation.MainOperation.GroupName.Contains('.'))
                {
                    groupNames = aggregateOperation.MainOperation.GroupName.Split('.').ToList();
                }
                else
                {
                    groupNames.Add(aggregateOperation.MainOperation.GroupName);
                }

                var leafGroup = GenerateGroupTree(groupNames, 0, restTocGroup);
                if (leafGroup.RestTocLeaves == null)
                {
                    leafGroup.RestTocLeaves = new List <GraphAggregateEntity>();
                }
                leafGroup.RestTocLeaves.Add(aggregateOperation);
            }
        }
Ejemplo n.º 2
0
        private RestTocGroup GenerateGroupTree(List <string> groupNames, int index, RestTocGroup parentGroup)
        {
            if (index < groupNames.Count)
            {
                var childGroup = parentGroup[groupNames[index]];
                if (childGroup == null)
                {
                    childGroup = new RestTocGroup
                    {
                        Name = groupNames[index]
                    };

                    parentGroup[groupNames[index]] = childGroup;
                }
                return(GenerateGroupTree(groupNames, index + 1, childGroup));
            }
            else
            {
                return(parentGroup);
            }
        }
Ejemplo n.º 3
0
 private void WriteOpeartions(string targetApiVersionDir, GraphAggregateResult aggregateResult, RestTocGroup restTocGroup, int depth)
 {
     if (restTocGroup != null)
     {
         foreach (var group in restTocGroup.Groups)
         {
             if (depth > 1)
             {
                 ResolveComponent(aggregateResult, MappingFile.ComponentPrefix + group.Key, group.Value);
             }
             WriteOpeartions(targetApiVersionDir, aggregateResult, group.Value, depth + 1);
         }
         if (restTocGroup.RestTocLeaves?.Count > 0)
         {
             var aggregateOperations = restTocGroup.RestTocLeaves.OrderBy(p => p.MainOperation.Name);
             foreach (var aggregateOperation in aggregateOperations)
             {
                 SplitHelper.WriteOperations(targetApiVersionDir, aggregateOperation, MergeOperations, MergeOperations);
             }
         }
     }
 }
Ejemplo n.º 4
0
 public override void WriteToc(string targetApiVersionDir, RestTocGroup restTocGroup)
 {
     // todo: remove the toc.yml
     base.WriteToc(targetApiVersionDir, restTocGroup);
 }
Ejemplo n.º 5
0
        public override void GenerateTocAndYamls(string targetApiVersionDir, SplitSwaggerResult splitSwaggerResult, RestTocGroup restTocGroup)
        {
            Console.WriteLine("Starting to aggregate split result");
            var aggregateResult = Aggregate(splitSwaggerResult);

            Console.WriteLine("Starting to generate toc for aggregated result");
            GenerateToc(restTocGroup, aggregateResult);

            Console.WriteLine($"Starting to create operation yamls");
            WriteOpeartions(targetApiVersionDir, aggregateResult, restTocGroup, 1);

            Console.WriteLine($"Starting to create component yamls");
            SplitHelper.WriteComponents(targetApiVersionDir, aggregateResult.Components);
        }
Ejemplo n.º 6
0
        private void ResolveComponent(GraphAggregateResult aggregateResult, string componentName, RestTocGroup restTocGroup)
        {
            foreach (var component in aggregateResult.Components)
            {
                if (string.Equals(component.Name, componentName, StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine($"Find the component: {componentName}, then adding operations and links");
                    component.Operations = component.Operations ?? new List <string>();
                    component.Links      = component.Links ?? new List <ResponseLinkEntity>();
                    if (restTocGroup.RestTocLeaves?.Count > 0)
                    {
                        foreach (var aggregateOperation in restTocGroup.RestTocLeaves)
                        {
                            if (!component.Operations.Any(o => o == aggregateOperation.MainOperation.Id))
                            {
                                component.Operations.Add(aggregateOperation.MainOperation.Id);
                            }

                            if (aggregateOperation.MainOperation.Responses?.Count > 0)
                            {
                                foreach (var response in aggregateOperation.MainOperation.Responses)
                                {
                                    if (response.ResponseLinks?.Count > 0)
                                    {
                                        foreach (var link in response.ResponseLinks)
                                        {
                                            if (!component.Links.Any(l => l.Key == link.Key))
                                            {
                                                if (aggregateResult.IdMappings.TryGetValue(link.OperationId, out var mainOperationId))
                                                {
                                                    component.Links.Add(new ResponseLinkEntity
                                                    {
                                                        Key         = link.Key,
                                                        OperationId = mainOperationId
                                                    });
                                                }
                                                else
                                                {
                                                    Console.WriteLine($"Can not get link operation id for {link.OperationId}");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    restTocGroup.Id = component.Id;
                    return;
                }
            }
            Console.WriteLine($"Cannot find the component: {componentName}");
        }