From f37d3e78d73387da5c46ce3a07726dfdf4a2594f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:57:41 +0000 Subject: [PATCH 1/6] Bump FluentAssertions from 6.9.0 to 6.10.0 Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 6.9.0 to 6.10.0. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/develop/AcceptApiChanges.ps1) - [Commits](https://github.com/fluentassertions/fluentassertions/compare/6.9.0...6.10.0) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Readers.Tests.csproj | 2 +- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index 9f780f605..bb4acc5d5 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -262,7 +262,7 @@ all - + diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index fc9274aea..f1f1d5599 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -23,7 +23,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + From 8de409e67417174ef2ce8126000330f95b0c62a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 21:57:37 +0000 Subject: [PATCH 2/6] Bump Verify.Xunit from 19.9.2 to 19.9.3 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 19.9.2 to 19.9.3. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/commits) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index f1f1d5599..b1cc820b6 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -28,7 +28,7 @@ - + all From e0472916ee3154dd4180d82194b442d97f0352e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Feb 2023 21:57:34 +0000 Subject: [PATCH 3/6] Bump Microsoft.OData.Edm from 7.14.0 to 7.14.1 Bumps Microsoft.OData.Edm from 7.14.0 to 7.14.1. --- updated-dependencies: - dependency-name: Microsoft.OData.Edm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index b30d770de..6ba69e598 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -42,7 +42,7 @@ - + From 622a6e20d5eed9201f3297d376a2ad497ab19af5 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 20 Feb 2023 15:11:44 -0500 Subject: [PATCH 4/6] - adds missing cancellation token parameter and passes it along --- src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 8 ++++---- src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs | 8 +++++--- src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs | 6 ++++-- .../OpenApiYamlDocumentReader.cs | 9 +++++---- .../Services/OpenApiWorkspaceLoader.cs | 8 ++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index fa0b5ff51..9fdca3f66 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -162,7 +162,7 @@ private static async Task GetOpenApi(string openapi, string csd else { stream = await GetStream(openapi, logger, cancellationToken); - var result = await ParseOpenApi(openapi, inlineExternal, logger, stream); + var result = await ParseOpenApi(openapi, inlineExternal, logger, stream, cancellationToken); document = result.OpenApiDocument; } @@ -253,7 +253,7 @@ public static async Task ValidateOpenApiDocument( { using var stream = await GetStream(openapi, logger, cancellationToken); - var result = await ParseOpenApi(openapi, false, logger, stream); + var result = await ParseOpenApi(openapi, false, logger, stream, cancellationToken); using (logger.BeginScope("Calculating statistics")) { @@ -275,7 +275,7 @@ public static async Task ValidateOpenApiDocument( } } - private static async Task ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream) + private static async Task ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken) { ReadResult result; Stopwatch stopwatch = Stopwatch.StartNew(); @@ -290,7 +290,7 @@ private static async Task ParseOpenApi(string openApiFile, bool inli new Uri(openApiFile) : new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar) } - ).ReadAsync(stream); + ).ReadAsync(stream, cancellationToken); logger.LogTrace("{timestamp}ms: Completed parsing.", stopwatch.ElapsedMilliseconds); diff --git a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs index 13bdbdef8..4529cb57e 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -54,8 +55,9 @@ public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic) /// Reads the stream input and parses it into an Open API document. /// /// Stream containing OpenAPI description to parse. + /// Cancellation token. /// Instance result containing newly created OpenApiDocument and diagnostics object from the process - public async Task ReadAsync(Stream input) + public async Task ReadAsync(Stream input, CancellationToken cancellationToken = default) { MemoryStream bufferedStream; if (input is MemoryStream) @@ -67,13 +69,13 @@ public async Task ReadAsync(Stream input) // Buffer stream so that OpenApiTextReaderReader can process it synchronously // YamlDocument doesn't support async reading. bufferedStream = new MemoryStream(); - await input.CopyToAsync(bufferedStream); + await input.CopyToAsync(bufferedStream, 81920, cancellationToken); bufferedStream.Position = 0; } var reader = new StreamReader(bufferedStream); - return await new OpenApiTextReaderReader(_settings).ReadAsync(reader); + return await new OpenApiTextReaderReader(_settings).ReadAsync(reader, cancellationToken); } /// diff --git a/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs index f4e81dee9..d6722d440 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -57,8 +58,9 @@ public OpenApiDocument Read(TextReader input, out OpenApiDiagnostic diagnostic) /// Reads the content of the TextReader. If there are references to external documents then they will be read asynchronously. /// /// TextReader containing OpenAPI description to parse. + /// Cancellation token. /// A ReadResult instance that contains the resulting OpenApiDocument and a diagnostics instance. - public async Task ReadAsync(TextReader input) + public async Task ReadAsync(TextReader input, CancellationToken cancellationToken = default) { YamlDocument yamlDocument; @@ -78,7 +80,7 @@ public async Task ReadAsync(TextReader input) }; } - return await new OpenApiYamlDocumentReader(this._settings).ReadAsync(yamlDocument); + return await new OpenApiYamlDocumentReader(this._settings).ReadAsync(yamlDocument, cancellationToken); } diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs index 37113578a..e43c64ac2 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Extensions; @@ -84,7 +85,7 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic return document; } - public async Task ReadAsync(YamlDocument input) + public async Task ReadAsync(YamlDocument input, CancellationToken cancellationToken = default) { var diagnostic = new OpenApiDiagnostic(); var context = new ParsingContext(diagnostic) @@ -101,7 +102,7 @@ public async Task ReadAsync(YamlDocument input) if (_settings.LoadExternalRefs) { - await LoadExternalRefs(document); + await LoadExternalRefs(document, cancellationToken); } ResolveReferences(diagnostic, document); @@ -132,7 +133,7 @@ public async Task ReadAsync(YamlDocument input) }; } - private async Task LoadExternalRefs(OpenApiDocument document) + private async Task LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken) { // Create workspace for all documents to live in. var openApiWorkSpace = new OpenApiWorkspace(); @@ -140,7 +141,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); - await workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document); + await workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document, cancellationToken); } private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document) diff --git a/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs b/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs index def92967e..32e2db128 100644 --- a/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs +++ b/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs @@ -3,11 +3,11 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.Interface; using Microsoft.OpenApi.Services; -using SharpYaml.Model; namespace Microsoft.OpenApi.Readers.Services { @@ -24,7 +24,7 @@ public OpenApiWorkspaceLoader(OpenApiWorkspace workspace, IStreamLoader loader, _readerSettings = readerSettings; } - internal async Task LoadAsync(OpenApiReference reference, OpenApiDocument document) + internal async Task LoadAsync(OpenApiReference reference, OpenApiDocument document, CancellationToken cancellationToken) { _workspace.AddDocument(reference.ExternalResource, document); document.Workspace = _workspace; @@ -43,8 +43,8 @@ internal async Task LoadAsync(OpenApiReference reference, OpenApiDocument docume if (!_workspace.Contains(item.ExternalResource)) { var input = await _loader.LoadAsync(new Uri(item.ExternalResource, UriKind.RelativeOrAbsolute)); - var result = await reader.ReadAsync(input); // TODO merge _diagnositics - await LoadAsync(item, result.OpenApiDocument); + var result = await reader.ReadAsync(input, cancellationToken); // TODO merge diagnostics + await LoadAsync(item, result.OpenApiDocument, cancellationToken); } } } From ce1864956f00b3ff7ed12d7f7563c9f5dad3fa48 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 20 Feb 2023 15:16:07 -0500 Subject: [PATCH 5/6] - fixes missing memory stream dispose Signed-off-by: Vincent Biret --- src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs index 4529cb57e..8922be4ce 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs @@ -73,9 +73,10 @@ public async Task ReadAsync(Stream input, CancellationToken cancella bufferedStream.Position = 0; } - var reader = new StreamReader(bufferedStream); - - return await new OpenApiTextReaderReader(_settings).ReadAsync(reader, cancellationToken); + using (var reader = new StreamReader(bufferedStream)) + { + return await new OpenApiTextReaderReader(_settings).ReadAsync(reader, cancellationToken); + } } /// From 70d0888e5ad17610aa85794708590f3159bd2016 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 20 Feb 2023 15:37:34 -0500 Subject: [PATCH 6/6] - bumps patch version Signed-off-by: Vincent Biret --- src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 781deb6ee..e095c6c86 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -10,7 +10,7 @@ Microsoft Microsoft.OpenApi.Readers Microsoft.OpenApi.Readers - 1.6.1 + 1.6.2 OpenAPI.NET Readers for JSON and YAML documents © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 622e7e7b6..92de7f8a0 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -11,7 +11,7 @@ Microsoft Microsoft.OpenApi Microsoft.OpenApi - 1.6.1 + 1.6.2 .NET models with JSON and YAML writers for OpenAPI specification © Microsoft Corporation. All rights reserved. OpenAPI .NET