From fc431205206514a95415fef4410c99f4cfa86561 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 2 Oct 2023 19:14:05 +1100 Subject: [PATCH 1/2] elide some asyncs --- src/Microsoft.OpenApi.Hidi/Program.cs | 4 ++-- .../OpenApiYamlDocumentReader.cs | 4 ++-- .../Services/OpenApiServiceTests.cs | 24 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Program.cs b/src/Microsoft.OpenApi.Hidi/Program.cs index b8508ab5f..9fe8a3014 100644 --- a/src/Microsoft.OpenApi.Hidi/Program.cs +++ b/src/Microsoft.OpenApi.Hidi/Program.cs @@ -12,12 +12,12 @@ namespace Microsoft.OpenApi.Hidi { static class Program { - static async Task Main(string[] args) + static Task Main(string[] args) { var rootCommand = CreateRootCommand(); // Parse the incoming args and invoke the handler - return await rootCommand.InvokeAsync(args).ConfigureAwait(false); + return rootCommand.InvokeAsync(args); } internal static RootCommand CreateRootCommand() diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs index 4a120cbbf..de7f810ad 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs @@ -140,7 +140,7 @@ public async Task ReadAsync(YamlDocument input, CancellationToken ca }; } - private async Task LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken) + private Task LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken) { // Create workspace for all documents to live in. var openApiWorkSpace = new OpenApiWorkspace(); @@ -148,7 +148,7 @@ private async Task LoadExternalRefs(OpenApiDocument document, // Load this root document into the workspace var streamLoader = new DefaultStreamLoader(_settings.BaseUrl); var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, _settings.CustomExternalLoader ?? streamLoader, _settings); - return await workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document, cancellationToken); + return workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document, cancellationToken); } private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index 9d73c8db6..24169045f 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -177,25 +177,25 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiag } [Fact] - public async Task ThrowIfOpenApiUrlIsNotProvidedWhenValidating() + public Task ThrowIfOpenApiUrlIsNotProvidedWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("", _logger, new CancellationToken())); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("", _logger, new CancellationToken())); } [Fact] - public async Task ThrowIfURLIsNotResolvableWhenValidating() + public Task ThrowIfURLIsNotResolvableWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("https://example.org/itdoesnmatter", _logger, new CancellationToken())); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("https://example.org/itdoesnmatter", _logger, new CancellationToken())); } [Fact] - public async Task ThrowIfFileDoesNotExistWhenValidating() + public Task ThrowIfFileDoesNotExistWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("aFileThatBetterNotExist.fake", _logger, new CancellationToken())); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("aFileThatBetterNotExist.fake", _logger, new CancellationToken())); } [Fact] @@ -285,7 +285,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAndSwitchF } [Fact] - public async Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() + public Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() { HidiOptions options = new HidiOptions { @@ -294,8 +294,8 @@ public async Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() InlineLocal = false, InlineExternal = false, }; - await Assert.ThrowsAsync(async () => - await OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken())); + return Assert.ThrowsAsync(() => + OpenApiService.TransformOpenApiDocument(options, _logger, new CancellationToken())); } From ed51df562f5d349a73ed5da673d27c59a6dba990 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 3 Oct 2023 09:41:41 +1100 Subject: [PATCH 2/2] . --- .../OpenApiYamlDocumentReader.cs | 4 +-- .../Services/OpenApiServiceTests.cs | 25 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs index 7388254c3..5053cbc7b 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs @@ -139,7 +139,7 @@ public async Task ReadAsync(YamlDocument input, CancellationToken ca }; } - private async Task LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken = default) + private Task LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken = default) { // Create workspace for all documents to live in. var openApiWorkSpace = new OpenApiWorkspace(); @@ -147,7 +147,7 @@ private async Task LoadExternalRefs(OpenApiDocument document, // Load this root document into the workspace var streamLoader = new DefaultStreamLoader(_settings.BaseUrl); var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, _settings.CustomExternalLoader ?? streamLoader, _settings); - return await workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, null, cancellationToken); + return workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, null, cancellationToken); } private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index 7e360bdfe..764d6903d 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -176,25 +176,25 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiag } [Fact] - public async Task ThrowIfOpenApiUrlIsNotProvidedWhenValidating() + public Task ThrowIfOpenApiUrlIsNotProvidedWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("", _logger)); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("", _logger)); } [Fact] - public async Task ThrowIfURLIsNotResolvableWhenValidating() + public Task ThrowIfURLIsNotResolvableWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("https://example.org/itdoesnmatter", _logger)); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("https://example.org/itdoesnmatter", _logger)); } [Fact] - public async Task ThrowIfFileDoesNotExistWhenValidating() + public Task ThrowIfFileDoesNotExistWhenValidating() { - await Assert.ThrowsAsync(async () => - await OpenApiService.ValidateOpenApiDocument("aFileThatBetterNotExist.fake", _logger)); + return Assert.ThrowsAsync(() => + OpenApiService.ValidateOpenApiDocument("aFileThatBetterNotExist.fake", _logger)); } [Fact] @@ -284,7 +284,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAndSwitchF } [Fact] - public async Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() + public Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() { HidiOptions options = new HidiOptions { @@ -293,9 +293,8 @@ public async Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty() InlineLocal = false, InlineExternal = false, }; - await Assert.ThrowsAsync(async () => - await OpenApiService.TransformOpenApiDocument(options, _logger)); - + return Assert.ThrowsAsync(() => + OpenApiService.TransformOpenApiDocument(options, _logger)); } [Fact]