Skip to content

Commit 71399f6

Browse files
committed
Code cleanup
1 parent 0cf947b commit 71399f6

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,29 @@ public static class OpenApiFilterService
6767
{
6868
var operationTypes = new List<string>();
6969

70-
var apiVersion = source.Info.Version;
71-
72-
var sources = new Dictionary<string, OpenApiDocument> {{ apiVersion, source}};
73-
var rootNode = CreateOpenApiUrlTreeNode(sources);
74-
75-
//Iterate through urls dictionary and fetch operations for each url
76-
foreach (var path in requestUrls)
70+
if (source != null)
7771
{
78-
var serverList = source.Servers;
79-
var url = FormatUrlString(path.Key, serverList);
72+
var apiVersion = source.Info.Version;
8073

81-
var openApiOperations = GetOpenApiOperations(rootNode, url, apiVersion);
82-
if (openApiOperations == null)
83-
{
84-
continue;
85-
}
74+
var sources = new Dictionary<string, OpenApiDocument> {{ apiVersion, source}};
75+
var rootNode = CreateOpenApiUrlTreeNode(sources);
8676

87-
foreach (var ops in openApiOperations)
77+
//Iterate through urls dictionary and fetch operations for each url
78+
foreach (var path in requestUrls)
8879
{
89-
operationTypes.Add(ops.Key + url);
80+
var serverList = source.Servers;
81+
var url = FormatUrlString(path.Key, serverList);
82+
83+
var openApiOperations = GetOpenApiOperations(rootNode, url, apiVersion);
84+
if (openApiOperations == null)
85+
{
86+
continue;
87+
}
88+
89+
foreach (var ops in openApiOperations)
90+
{
91+
operationTypes.Add(ops.Key + url);
92+
}
9093
}
9194
}
9295

@@ -199,10 +202,8 @@ public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream st
199202
using var document = JsonDocument.Parse(stream);
200203
var root = document.RootElement;
201204
var itemElement = root.GetProperty("item");
202-
foreach(JsonElement item in itemElement.EnumerateArray())
205+
foreach(var requestObject in itemElement.EnumerateArray().Select(item => item.GetProperty("request")))
203206
{
204-
var requestObject = item.GetProperty("request");
205-
206207
// Fetch list of methods and urls from collection, store them in a dictionary
207208
var path = requestObject.GetProperty("url").GetProperty("raw").ToString();
208209
var method = requestObject.GetProperty("method").ToString();

0 commit comments

Comments
 (0)