diff --git a/OpenAPIService.Test/OpenAPIServiceShould.cs b/OpenAPIService.Test/OpenAPIServiceShould.cs index 0f98f1ff3..58d8f419a 100644 --- a/OpenAPIService.Test/OpenAPIServiceShould.cs +++ b/OpenAPIService.Test/OpenAPIServiceShould.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Text.Json; +using System.Threading.Tasks; using Microsoft.OpenApi; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -584,7 +585,7 @@ public void SetByRefPostfixForRefOperationIds() } [Fact] - public void GetOpenApiTreeNode() + public async Task GetOpenApiTreeNodeAsync() { // Arrange var sources = new ConcurrentDictionary(); @@ -593,7 +594,7 @@ public void GetOpenApiTreeNode() // Act var rootNode = _openApiService.CreateOpenApiUrlTreeNode(sources); using MemoryStream stream = new(); - ConvertOpenApiUrlTreeNodeToJson(rootNode, stream); + await ConvertOpenApiUrlTreeNodeToJsonAsync(rootNode, stream); // Assert var jsonPayload = Encoding.ASCII.GetString(stream.ToArray()); @@ -720,10 +721,10 @@ public void ConvertOpenApiUrlTreeNodeToJsonRendersExternalDocs() Assert.Contains("\"children\":[{\"segment\":\"{user-id}\",\"labels\":[{\"name\":\"mock\",\"methods\":[{\"name\":\"Get\",\"documentationUrl\":\"https://docs.microsoft.com/foobar\"}", output); } - private void ConvertOpenApiUrlTreeNodeToJson(OpenApiUrlTreeNode node, Stream stream) + private async Task ConvertOpenApiUrlTreeNodeToJsonAsync(OpenApiUrlTreeNode node, Stream stream) { Assert.NotNull(node); - _openApiService.ConvertOpenApiUrlTreeNodeToJson(node, stream); + await _openApiService.ConvertOpenApiUrlTreeNodeToJsonAsync(node, stream); Assert.True(stream.Length > 0); } } diff --git a/OpenAPIService/Interfaces/IOpenApiService.cs b/OpenAPIService/Interfaces/IOpenApiService.cs index d6df9a39a..c9baea41d 100644 --- a/OpenAPIService/Interfaces/IOpenApiService.cs +++ b/OpenAPIService/Interfaces/IOpenApiService.cs @@ -25,7 +25,7 @@ Func CreatePredicate(string operationIds, string tags, s OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(ConcurrentDictionary sources); - void ConvertOpenApiUrlTreeNodeToJson(OpenApiUrlTreeNode rootNode, Stream stream); + Task ConvertOpenApiUrlTreeNodeToJsonAsync(OpenApiUrlTreeNode rootNode, Stream stream); OpenApiDocument ApplyStyle(OpenApiStyle style, OpenApiDocument subsetOpenApiDocument, bool includeRequestBody = false, bool singularizeOperationIds = false); diff --git a/OpenAPIService/OpenApiService.cs b/OpenAPIService/OpenApiService.cs index 0cc59bb4a..fe84c0401 100644 --- a/OpenAPIService/OpenApiService.cs +++ b/OpenAPIService/OpenApiService.cs @@ -394,11 +394,11 @@ private OpenApiOperation[] GetOpenApiOperations(OpenApiUrlTreeNode rootNode, str /// /// The target root node. /// The destination for writing the JSON text to. - public void ConvertOpenApiUrlTreeNodeToJson(OpenApiUrlTreeNode rootNode, Stream stream) + public async Task ConvertOpenApiUrlTreeNodeToJsonAsync(OpenApiUrlTreeNode rootNode, Stream stream) { using Utf8JsonWriter writer = new Utf8JsonWriter(stream); ConvertOpenApiUrlTreeNodeToJson(writer, rootNode); - writer.FlushAsync(); + await writer.FlushAsync(); } ///