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); } }
private GraphAggregateResult Aggregate(SplitSwaggerResult splitSwaggerResult) { var aggregatedResult = new GraphAggregateResult { Components = splitSwaggerResult.ComponentGroup.Components }; foreach (var operationGroup in splitSwaggerResult.OperationGroups) { foreach (var operation in operationGroup.Operations) { if (operation.IsMainOperation == null) { OperationEntity mainOperation; List <OperationEntity> groupedOperations = new List <OperationEntity>(); if (operation.GroupedPaths.Count > 0) { var paths = new List <string>() { operation.Paths[0] }; paths.AddRange(operation.GroupedPaths); var calculatedResult = CalculateAggregatenPath(paths); var mainOperationId = FindOperationId(splitSwaggerResult, calculatedResult.Item1, operation.HttpVerb, out var foundMainOperation); aggregatedResult.IdMappings[mainOperationId] = mainOperationId; foundMainOperation.IsMainOperation = true; mainOperation = foundMainOperation; foreach (var path in calculatedResult.Item2) { var opeartionId = FindOperationId(splitSwaggerResult, path, operation.HttpVerb, out var foundOperation); aggregatedResult.IdMappings[opeartionId] = mainOperationId; foundOperation.IsMainOperation = false; groupedOperations.Add(foundOperation); } } else { operation.IsMainOperation = true; aggregatedResult.IdMappings[operation.Id] = operation.Id; mainOperation = operation; } aggregatedResult.AggregateOperations.Add(new GraphAggregateEntity { MainOperation = mainOperation, GroupedOperations = groupedOperations, IsFunctionOrAction = operation.IsFunctionOrAction }); } } } return(aggregatedResult); }
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}"); }
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); } } } }