Example #1
0
        private static void AddAllPathsEntries(OpenApiUrlTreeNode currentNode, Dictionary <string, HashSet <OpenApiUrlTreeNode> > index, string label)
        {
            if (currentNode == null || string.IsNullOrEmpty(label))
            {
                return;
            }

            if (currentNode.PathItems.ContainsKey(label) && currentNode.HasOperations(label))
            {
                var nodeOperations            = currentNode.PathItems[label].Operations.Values;
                var requestSchemasFirstLevel  = nodeOperations.SelectMany(x => x.RequestBody?.Content?.Values?.Select(y => y.Schema) ?? Enumerable.Empty <OpenApiSchema>());
                var responseSchemasFirstLevel = nodeOperations.SelectMany(x =>
                                                                          x?.Responses?.Values?.SelectMany(y =>
                                                                                                           y?.Content?.Values?.Select(z => z.Schema) ?? Enumerable.Empty <OpenApiSchema>()) ?? Enumerable.Empty <OpenApiSchema>());
                var operationFirstLevelSchemas = requestSchemasFirstLevel.Union(responseSchemasFirstLevel);

                operationFirstLevelSchemas.SelectMany(x => x.GetSchemaReferenceIds()).ToList().ForEach(x => {
                    if (index.TryGetValue(x, out var entry))
                    {
                        entry.Add(currentNode);
                    }
                    else
                    {
                        index.Add(x, new(new [] { currentNode }));
                    }
                });
            }

            if (currentNode.Children != null)
            {
                foreach (var child in currentNode.Children.Values)
                {
                    AddAllPathsEntries(child, index, label);
                }
            }
        }