Skip to content

Commit

Permalink
Merge pull request #1364 from SimonCropp/fix-some-warnings
Browse files Browse the repository at this point in the history
fix some warnings
  • Loading branch information
andrueastman authored Oct 2, 2023
2 parents 4b5f562 + 7fe922d commit 7857663
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
if (!string.IsNullOrEmpty(options.FilterOptions?.FilterByCollection))
{
using var collectionStream = await GetStream(options.FilterOptions.FilterByCollection, logger, cancellationToken).ConfigureAwait(false);
postmanCollection = JsonDocument.Parse(collectionStream);
postmanCollection = await JsonDocument.ParseAsync(collectionStream, cancellationToken: cancellationToken).ConfigureAwait(false);
}

// Load OpenAPI document
Expand Down Expand Up @@ -132,7 +132,8 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
}
using (var fileStream = await GetStream(apiManifestRef[0], logger, cancellationToken).ConfigureAwait(false))
{
apiManifest = ApiManifestDocument.Load(JsonDocument.Parse(fileStream).RootElement);
var document = await JsonDocument.ParseAsync(fileStream, cancellationToken: cancellationToken).ConfigureAwait(false);
apiManifest = ApiManifestDocument.Load(document.RootElement);
}

apiDependency = !string.IsNullOrEmpty(apiDependencyName) && apiManifest.ApiDependencies.TryGetValue(apiDependencyName, out var dependency) ? dependency : apiManifest.ApiDependencies.First().Value;
Expand Down Expand Up @@ -453,13 +454,13 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
// Fetch list of methods and urls from collection, store them in a dictionary
var path = request.GetProperty("url").GetProperty("raw").ToString();
var method = request.GetProperty("method").ToString();
if (!paths.ContainsKey(path))
if (paths.TryGetValue(path, out var value))
{
paths.Add(path, new List<string> { method });
value.Add(method);
}
else
{
paths[path].Add(method);
paths.Add(path, new List<string> {method});
}
}
else
Expand Down Expand Up @@ -755,7 +756,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
using var file = new FileStream(manifestFile.FullName, FileMode.Create);
using var jsonWriter = new Utf8JsonWriter(file, new JsonWriterOptions { Indented = true });
manifest.Write(jsonWriter);
jsonWriter.Flush();
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram()

await OpenApiService.ShowOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText(options.Output.FullName);
var output = await File.ReadAllTextAsync(options.Output.FullName);
Assert.Contains("graph LR", output, StringComparison.Ordinal);
}

Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiag
// create a dummy ILogger instance for testing
await OpenApiService.ShowOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText(options.Output.FullName);
var output = await File.ReadAllTextAsync(options.Output.FullName);
Assert.Contains("graph LR", output, StringComparison.Ordinal);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task TransformCommandConvertsOpenApi()
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText("sample.json");
var output = await File.ReadAllTextAsync("sample.json");
Assert.NotEmpty(output);
}

Expand All @@ -242,7 +242,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputName()
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText("output.yml");
var output = await File.ReadAllTextAsync("output.yml");
Assert.NotEmpty(output);
}

Expand All @@ -260,7 +260,7 @@ public async Task TransformCommandConvertsCsdlWithDefaultOutputName()
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText("output.yml");
var output = await File.ReadAllTextAsync("output.yml");
Assert.NotEmpty(output);
}

Expand All @@ -280,7 +280,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAndSwitchF
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText("output.yml");
var output = await File.ReadAllTextAsync("output.yml");
Assert.NotEmpty(output);
}

Expand Down Expand Up @@ -317,7 +317,7 @@ public async Task TransformToPowerShellCompliantOpenApi()
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken());

var output = File.ReadAllText("output.yml");
var output = await File.ReadAllTextAsync("output.yml");
Assert.NotEmpty(output);
}

Expand Down

0 comments on commit 7857663

Please sign in to comment.