Skip to content

Commit 7fe922d

Browse files
committed
fix some warnings
1 parent 4b5f562 commit 7fe922d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
8181
if (!string.IsNullOrEmpty(options.FilterOptions?.FilterByCollection))
8282
{
8383
using var collectionStream = await GetStream(options.FilterOptions.FilterByCollection, logger, cancellationToken).ConfigureAwait(false);
84-
postmanCollection = JsonDocument.Parse(collectionStream);
84+
postmanCollection = await JsonDocument.ParseAsync(collectionStream, cancellationToken: cancellationToken).ConfigureAwait(false);
8585
}
8686

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

138139
apiDependency = !string.IsNullOrEmpty(apiDependencyName) && apiManifest.ApiDependencies.TryGetValue(apiDependencyName, out var dependency) ? dependency : apiManifest.ApiDependencies.First().Value;
@@ -453,13 +454,13 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
453454
// Fetch list of methods and urls from collection, store them in a dictionary
454455
var path = request.GetProperty("url").GetProperty("raw").ToString();
455456
var method = request.GetProperty("method").ToString();
456-
if (!paths.ContainsKey(path))
457+
if (paths.TryGetValue(path, out var value))
457458
{
458-
paths.Add(path, new List<string> { method });
459+
value.Add(method);
459460
}
460461
else
461462
{
462-
paths[path].Add(method);
463+
paths.Add(path, new List<string> {method});
463464
}
464465
}
465466
else
@@ -755,7 +756,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
755756
using var file = new FileStream(manifestFile.FullName, FileMode.Create);
756757
using var jsonWriter = new Utf8JsonWriter(file, new JsonWriterOptions { Indented = true });
757758
manifest.Write(jsonWriter);
758-
jsonWriter.Flush();
759+
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
759760
}
760761
}
761762
}

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram()
144144

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

147-
var output = File.ReadAllText(options.Output.FullName);
147+
var output = await File.ReadAllTextAsync(options.Output.FullName);
148148
Assert.Contains("graph LR", output, StringComparison.Ordinal);
149149
}
150150

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

175-
var output = File.ReadAllText(options.Output.FullName);
175+
var output = await File.ReadAllTextAsync(options.Output.FullName);
176176
Assert.Contains("graph LR", output, StringComparison.Ordinal);
177177
}
178178

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

226-
var output = File.ReadAllText("sample.json");
226+
var output = await File.ReadAllTextAsync("sample.json");
227227
Assert.NotEmpty(output);
228228
}
229229

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

245-
var output = File.ReadAllText("output.yml");
245+
var output = await File.ReadAllTextAsync("output.yml");
246246
Assert.NotEmpty(output);
247247
}
248248

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

263-
var output = File.ReadAllText("output.yml");
263+
var output = await File.ReadAllTextAsync("output.yml");
264264
Assert.NotEmpty(output);
265265
}
266266

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

283-
var output = File.ReadAllText("output.yml");
283+
var output = await File.ReadAllTextAsync("output.yml");
284284
Assert.NotEmpty(output);
285285
}
286286

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

320-
var output = File.ReadAllText("output.yml");
320+
var output = await File.ReadAllTextAsync("output.yml");
321321
Assert.NotEmpty(output);
322322
}
323323

0 commit comments

Comments
 (0)