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); }
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); }
private string FindOperationId(SplitSwaggerResult splitSwaggerResult, string path, string httpVerb, out OperationEntity foundOperation) { foreach (var operationGroup in splitSwaggerResult.OperationGroups) { foreach (var operation in operationGroup.Operations) { if (string.Equals(path, operation.Paths[0], StringComparison.OrdinalIgnoreCase) && string.Equals(httpVerb, operation.HttpVerb)) { foundOperation = operation; return(operation.Id); } } } throw new Exception($"Can not find the operation id by x-ms-docs-grouped-path: {path} and httpVerb: {httpVerb}"); }