|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | using System;
|
@@ -301,24 +301,41 @@ public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream st
|
301 | 301 | logger.LogTrace("Parsing the json collection file into a JsonDocument");
|
302 | 302 | using var document = JsonDocument.Parse(stream);
|
303 | 303 | var root = document.RootElement;
|
304 |
| - var itemElement = root.GetProperty("item"); |
305 |
| - foreach (var requestObject in itemElement.EnumerateArray().Select(item => item.GetProperty("request"))) |
306 |
| - { |
307 |
| - // Fetch list of methods and urls from collection, store them in a dictionary |
308 |
| - var path = requestObject.GetProperty("url").GetProperty("raw").ToString(); |
309 |
| - var method = requestObject.GetProperty("method").ToString(); |
310 | 304 |
|
311 |
| - if (!requestUrls.ContainsKey(path)) |
| 305 | + requestUrls = Enumerate(root, requestUrls); |
| 306 | + |
| 307 | + logger.LogTrace("Finished fetching the list of paths and Http methods defined in the Postman collection."); |
| 308 | + return requestUrls; |
| 309 | + } |
| 310 | + |
| 311 | + private static Dictionary<string, List<string>> Enumerate(JsonElement itemElement, Dictionary<string, List<string>> paths) |
| 312 | + { |
| 313 | + var itemsArray = itemElement.GetProperty("item"); |
| 314 | + |
| 315 | + foreach (var item in itemsArray.EnumerateArray()) |
| 316 | + { |
| 317 | + if (item.TryGetProperty("request", out var request)) |
312 | 318 | {
|
313 |
| - requestUrls.Add(path, new List<string> { method }); |
| 319 | + // Fetch list of methods and urls from collection, store them in a dictionary |
| 320 | + var path = request.GetProperty("url").GetProperty("raw").ToString(); |
| 321 | + var method = request.GetProperty("method").ToString(); |
| 322 | + |
| 323 | + if (!paths.ContainsKey(path)) |
| 324 | + { |
| 325 | + paths.Add(path, new List<string> { method }); |
| 326 | + } |
| 327 | + else |
| 328 | + { |
| 329 | + paths[path].Add(method); |
| 330 | + } |
314 | 331 | }
|
315 | 332 | else
|
316 | 333 | {
|
317 |
| - requestUrls[path].Add(method); |
| 334 | + Enumerate(item, paths); |
318 | 335 | }
|
319 | 336 | }
|
320 |
| - logger.LogTrace("Finished fetching the list of paths and Http methods defined in the Postman collection."); |
321 |
| - return requestUrls; |
| 337 | + |
| 338 | + return paths; |
322 | 339 | }
|
323 | 340 |
|
324 | 341 | internal static async Task<int> ValidateOpenApiDocument(string openapi, LogLevel loglevel, CancellationToken cancellationToken)
|
|
0 commit comments