static async Task <SwaggerDocObject> Get(HttpClient client) { if (_swaggerResponse != null) { return(_swaggerResponse); } foreach (var possibleSwaggerUrl in PossibleSwaggerUrls) { try { var swaggerResponse = await client.GetAsync(possibleSwaggerUrl, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token); if (swaggerResponse.IsSuccessStatusCode) { var swaggerDocObject = JsonConvert.DeserializeObject <SwaggerDocObject>(await swaggerResponse.Content.ReadAsStringAsync()); _swaggerResponse = swaggerDocObject; return(swaggerDocObject); } } catch (Exception) { LogWarning($"Timed out fetching Swagger {possibleSwaggerUrl}"); } } LogError($"Could not find any valid swagger JSON document at {client.BaseAddress} | {string.Join(", ", PossibleSwaggerUrls)}"); return(null); }
static List <SwaggerUrlWithData> Map(SwaggerDocObject swaggerDocObject, TestRun testRun) { var urls = swaggerDocObject.paths.Where(x => x.Value.get != null).Select(x => new SwaggerUrl { Url = MapUrl(x, swaggerDocObject.basePath, testRun), Method = HttpMethod.Get }).Concat(swaggerDocObject.paths.Where(x => x.Value.post != null).Select(x => new SwaggerUrl { Url = MapUrl(x, swaggerDocObject.basePath, testRun), Method = HttpMethod.Post })).ToArray(); return(ExpandUrls(urls, testRun).DistinctBy(x => new { x.Url, x.Method.Method, FileName = x.FileNameFullPath }).ToList()); }