From 5fa4cf0876c5573012d8e9677d0b16b92037550a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 21:45:01 +0000 Subject: [PATCH 01/21] Bump Microsoft.Windows.Compatibility from 8.0.5 to 8.0.6 Bumps [Microsoft.Windows.Compatibility](https://github.com/dotnet/windowsdesktop) from 8.0.5 to 8.0.6. - [Release notes](https://github.com/dotnet/windowsdesktop/releases) - [Commits](https://github.com/dotnet/windowsdesktop/compare/v8.0.5...v8.0.6) --- updated-dependencies: - dependency-name: Microsoft.Windows.Compatibility dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Workbench.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index 41731665b..76c67aeeb 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -9,7 +9,7 @@ - + From 1c4d227f58a3e1ed2b270807e317341603a35d9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:14:29 +0000 Subject: [PATCH 02/21] Bump Microsoft.OData.Edm from 7.21.2 to 7.21.3 Bumps Microsoft.OData.Edm from 7.21.2 to 7.21.3. --- 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 3ef589659..1d869fab6 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -34,7 +34,7 @@ - + From 53a5621272a39dc5c33424321705e85027e862e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:53:25 +0300 Subject: [PATCH 03/21] Bump Verify.Xunit from 24.2.0 to 25.0.1 (#1685) Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 24.2.0 to 25.0.1. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/commits/25.0.1) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- 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 54714c352..a516ec7e5 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -15,7 +15,7 @@ - + From 2049b7379e4a7461c54fa8e11b8c7837e0981f8b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:55:26 +0300 Subject: [PATCH 04/21] Bump docker/login-action from 3.1.0 to 3.2.0 (#1683) Bumps [docker/login-action](https://github.com/docker/login-action) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v3.1.0...v3.2.0) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3895975fc..aa357a121 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -17,7 +17,7 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 - name: Login to GitHub package feed - uses: docker/login-action@v3.1.0 + uses: docker/login-action@v3.2.0 with: username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_PASSWORD }} From 71beac4bc5bcdd1b9b6c0e0071824662ca880043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kurai=20Andr=C3=A1s?= Date: Fri, 7 Jun 2024 11:34:31 +0200 Subject: [PATCH 05/21] Return -1 exit code when the document is not valid --- .../Handlers/ValidateCommandHandler.cs | 4 +-- src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 11 ++++++-- .../Services/OpenApiServiceTests.cs | 25 +++++++++++++++++++ .../UtilityFiles/InvalidSampleOpenApi.yml | 19 ++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/InvalidSampleOpenApi.yml diff --git a/src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs b/src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs index e0bfbf6b3..4c14cbef6 100644 --- a/src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs +++ b/src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs @@ -33,8 +33,8 @@ public async Task InvokeAsync(InvocationContext context) try { if (hidiOptions.OpenApi is null) throw new InvalidOperationException("OpenApi file is required"); - await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false); - return 0; + var isValid = await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false); + return isValid is not false ? 0 : -1; } #if RELEASE #pragma warning disable CA1031 // Do not catch general exception types diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index f33fc61da..d3d3fdd8c 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -322,7 +322,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe /// /// Implementation of the validate command /// - public static async Task ValidateOpenApiDocument( + /// when valid, when invalid and when cancelled + public static async Task ValidateOpenApiDocument( string openApi, ILogger logger, CancellationToken cancellationToken = default) @@ -332,11 +333,13 @@ public static async Task ValidateOpenApiDocument( throw new ArgumentNullException(nameof(openApi)); } + ReadResult? result = null; + try { using var stream = await GetStream(openApi, logger, cancellationToken).ConfigureAwait(false); - var result = await ParseOpenApi(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false); + result = await ParseOpenApi(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false); using (logger.BeginScope("Calculating statistics")) { @@ -358,6 +361,10 @@ public static async Task ValidateOpenApiDocument( { throw new InvalidOperationException($"Could not validate the document, reason: {ex.Message}", ex); } + + if (result is null) return null; + + return result.OpenApiDiagnostic.Errors.Count == 0; } private static async Task ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index f7c5aab45..7314da8ab 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -203,6 +203,31 @@ public async Task ValidateCommandProcessesOpenApi() Assert.True(true); } + [Fact] + public async Task ValidFileReturnsTrue() + { + var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger); + + Assert.True(isValid); + } + + [Fact] + public async Task InvalidFileReturnsFalse() + { + var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "InvalidSampleOpenApi.yml"), _logger); + + Assert.False(isValid); + } + + [Fact] + public async Task CancellingValidationReturnsNull() + { + using var cts = new CancellationTokenSource(); + await cts.CancelAsync(); + var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger, cts.Token); + + Assert.Null(isValid); + } [Fact] public async Task TransformCommandConvertsOpenApi() diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/InvalidSampleOpenApi.yml b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/InvalidSampleOpenApi.yml new file mode 100644 index 000000000..772214f5a --- /dev/null +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/InvalidSampleOpenApi.yml @@ -0,0 +1,19 @@ +openapi: 3.0.0 +info: + title: Sample OpenApi + version: 1.0.0 +paths: + /api/editresource: + get: + operationId: api.ListEditresource + patch: + operationId: api.UpdateEditresource + responses: + '200': + description: OK + /api/viewresource: + get: + operationId: api.ListViewresource + responses: + '200': + description: OK \ No newline at end of file From d2fe762a4a47cfba7c56dedeffa9bda71a396c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kurai=20Andr=C3=A1s?= Date: Fri, 7 Jun 2024 12:05:33 +0200 Subject: [PATCH 06/21] Change to relative path in `Launch Hidi` task --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c8714e62e..2fa4340b3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.dll", "args": ["plugin", - "-m","C:\\Users\\darrmi\\src\\github\\microsoft\\openapi.net\\test\\Microsoft.OpenApi.Hidi.Tests\\UtilityFiles\\exampleapimanifest.json", + "-m","${workspaceFolder}/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/exampleapimanifest.json", "--of","./output"], "cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console From 5a8384043b94e8f9fd377b40ea5167574e0e25bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 21:14:48 +0000 Subject: [PATCH 07/21] Bump docker/build-push-action from 5.3.0 to 5.4.0 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5.3.0 to 5.4.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5.3.0...v5.4.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index aa357a121..44ae4d602 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,13 +30,13 @@ jobs: id: getversion - name: Push to GitHub Packages - Nightly if: ${{ github.ref == 'refs/heads/vnext' }} - uses: docker/build-push-action@v5.3.0 + uses: docker/build-push-action@v5.4.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly - name: Push to GitHub Packages - Release if: ${{ github.ref == 'refs/heads/master' }} - uses: docker/build-push-action@v5.3.0 + uses: docker/build-push-action@v5.4.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }} From bbc31f5d9850c02dcb277225f992552675b89b31 Mon Sep 17 00:00:00 2001 From: Irvine Sunday <40403681+irvinesunday@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:11:33 +0300 Subject: [PATCH 08/21] Update conversion lib. version (#1689) --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 1d869fab6..01e5c1427 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -9,7 +9,7 @@ enable hidi ./../../artifacts - 1.4.4 + 1.4.5 OpenAPI.NET CLI tool for slicing OpenAPI documents true @@ -35,7 +35,7 @@ - + From f8ba5760d77f072e3378852fec0ad521f8dacf25 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 11 Jun 2024 15:37:50 +0300 Subject: [PATCH 09/21] Bump lib versions --- 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 d73767375..3bbbe339d 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -3,7 +3,7 @@ netstandard2.0 latest true - 1.6.14 + 1.6.15 OpenAPI.NET Readers for JSON and YAML documents true diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 45b707c96..ff795f27a 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -3,7 +3,7 @@ netstandard2.0 Latest true - 1.6.14 + 1.6.15 .NET models with JSON and YAML writers for OpenAPI specification true From a1aa6eebd8e707852a5a1a56ef59553e5b0ec815 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:18:06 +0000 Subject: [PATCH 10/21] Bump Verify.Xunit from 25.0.1 to 25.0.2 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 25.0.1 to 25.0.2. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/25.0.1...25.0.2) --- 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 a516ec7e5..089d1d5ce 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -15,7 +15,7 @@ - + From 5261400de87a168ef1e321b3d1326718a24673cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 21:16:06 +0000 Subject: [PATCH 11/21] Bump Verify.Xunit from 25.0.2 to 25.0.3 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 25.0.2 to 25.0.3. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/25.0.2...25.0.3) --- 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 089d1d5ce..ab7ef80f3 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -15,7 +15,7 @@ - + From 5f5fa02f14a186dbdb0f5a53920060af6bf8dd59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:43:28 +0000 Subject: [PATCH 12/21] Bump docker/build-push-action from 5.4.0 to 6.0.0 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5.4.0 to 6.0.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5.4.0...v6.0.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 44ae4d602..d0c4264f2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,13 +30,13 @@ jobs: id: getversion - name: Push to GitHub Packages - Nightly if: ${{ github.ref == 'refs/heads/vnext' }} - uses: docker/build-push-action@v5.4.0 + uses: docker/build-push-action@v6.0.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly - name: Push to GitHub Packages - Release if: ${{ github.ref == 'refs/heads/master' }} - uses: docker/build-push-action@v5.4.0 + uses: docker/build-push-action@v6.0.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }} From b26bd6ebe94a3cd39da7dfb3a33ecddad0863fbf Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 20 Jun 2024 20:34:22 +0300 Subject: [PATCH 13/21] Update the error message to insert the value of the referenceType --- src/Microsoft.OpenApi/Properties/SRResource.Designer.cs | 4 ++-- src/Microsoft.OpenApi/Properties/SRResource.resx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs b/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs index abf945258..1a9ab3014 100644 --- a/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs +++ b/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs @@ -124,7 +124,7 @@ internal static string InvalidReferenceId { } /// - /// Looks up a localized string similar to Invalid Reference Type.. + /// Looks up a localized string similar to Invalid Reference Type '{0}'.. /// internal static string InvalidReferenceType { get { @@ -340,7 +340,7 @@ internal static string Validation_PathItemMustBeginWithSlash { } /// - /// Looks up a localized string similar to The path signature '{0}' MUST begin be unique.. + /// Looks up a localized string similar to The path signature '{0}' MUST be unique.. /// internal static string Validation_PathSignatureMustBeUnique { get { diff --git a/src/Microsoft.OpenApi/Properties/SRResource.resx b/src/Microsoft.OpenApi/Properties/SRResource.resx index 38c4763d4..f0bb497d3 100644 --- a/src/Microsoft.OpenApi/Properties/SRResource.resx +++ b/src/Microsoft.OpenApi/Properties/SRResource.resx @@ -139,7 +139,7 @@ Invalid Reference identifier '{0}'. - Invalid Reference Type. + Invalid Reference Type '{0}'. Local reference must have type specified. From 71de0e0bf8bc4d13b1c637e3c6a08f519528ff7e Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 20 Jun 2024 20:35:20 +0300 Subject: [PATCH 14/21] Add a check to ascertain that the referenceType and the referencedObject matches; if not, throw an exception --- src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs b/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs index dd98b4317..00c069f30 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs @@ -259,6 +259,13 @@ private void ResolveTags(IList tags) { try { + var referencedObject = typeof(T).Name; + var referenceType = reference?.Type.ToString(); + if (referenceType is not null && !referencedObject.Contains(referenceType)) + { + throw new OpenApiException(string.Format(Properties.SRResource.InvalidReferenceType, referenceType)); + } + return _currentDocument.ResolveReference(reference, false) as T; } catch (OpenApiException ex) From f9fc4dbf0227724c4a069769ace15048c8c36d17 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 20 Jun 2024 20:35:32 +0300 Subject: [PATCH 15/21] Add test to validate --- .../V3Tests/OpenApiDocumentTests.cs | 12 +++++++++ .../OpenApiDocument/docWithWrongRef.json | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithWrongRef.json diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index a9401897b..d67c0054f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -9,8 +9,10 @@ using System.Threading; using FluentAssertions; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Readers.Interface; using Microsoft.OpenApi.Validations; using Microsoft.OpenApi.Validations.Rules; using Microsoft.OpenApi.Writers; @@ -1355,5 +1357,15 @@ public void ValidateExampleShouldNotHaveDataTypeMismatch() var warnings = diagnostic.Warnings; Assert.False(warnings.Any()); } + + [Fact] + public void ParseDocumetWithWrongReferenceTypeShouldReturnADiagnosticError() + { + using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithWrongRef.json")); + _ = new OpenApiStreamReader().Read(stream, out var diagnostic); + + diagnostic.Errors.Should().BeEquivalentTo(new List { + new( new OpenApiException("Invalid Reference Type 'Schema'.")) }); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithWrongRef.json b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithWrongRef.json new file mode 100644 index 000000000..6edf46be8 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithWrongRef.json @@ -0,0 +1,27 @@ +{ + "openapi":"3.0.0", + "info":{ + "title":"some api", + "description":"some description", + "version": "1" + }, + "servers":[{"url":"https://localhost"}], + "paths":{ + "/count":{ + "get":{ + "responses":{ + "200":{ + "$ref":"#/components/schemas/count" + }, + }, + } + } + }, + "components":{ + "schemas":{ + "count":{ + "type": "number" + } + } + } +} \ No newline at end of file From 2bb12033a171b25df1ecdd96e40fd48bd896b004 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Mon, 24 Jun 2024 12:18:39 +0300 Subject: [PATCH 16/21] Update logic to guard against null exceptions --- .../V2/OpenApiV2Deserializer.cs | 10 +++++----- .../V3/OpenApiV3Deserializer.cs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs index 8b10bb83f..790940759 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -113,11 +113,11 @@ public static IOpenApiAny LoadAny(ParseNode node) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - if (node.Context.ExtensionParsers.TryGetValue(name, out var parser)) + if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser( + OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()), + OpenApiSpecVersion.OpenApi2_0) is { } result) { - return parser( - OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()), - OpenApiSpecVersion.OpenApi2_0); + return result; } else { diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs index 79b5f0671..558864854 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs @@ -171,11 +171,11 @@ public static IOpenApiAny LoadAny(ParseNode node) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - if (node.Context.ExtensionParsers.TryGetValue(name, out var parser)) + if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser( + OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()), + OpenApiSpecVersion.OpenApi3_0) is { } result) { - return parser( - OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()), - OpenApiSpecVersion.OpenApi3_0); + return result; } else { From d7588036d4cc02e47e1d0b94f110e9aafb32b830 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Mon, 24 Jun 2024 12:20:32 +0300 Subject: [PATCH 17/21] Update extensions to return null instead of throwing --- .../MicrosoftExtensions/OpenApiDeprecationExtension.cs | 2 +- .../MicrosoftExtensions/OpenApiEnumFlagsExtension.cs | 2 +- .../OpenApiEnumValuesDescriptionExtension.cs | 2 +- .../MicrosoftExtensions/OpenApiPagingExtension.cs | 2 +- .../OpenApiPrimaryErrorMessageExtension.cs | 4 ++-- .../MicrosoftExtensions/OpenApiReservedParameterExtension.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs index 25a3b56a5..683082e2c 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs @@ -78,7 +78,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiDeprecationExtension Parse(IOpenApiAny source) { - if (source is not OpenApiObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiObject rawObject) return null; var extension = new OpenApiDeprecationExtension(); if (rawObject.TryGetValue(nameof(RemovalDate).ToFirstCharacterLowerCase(), out var removalDate) && removalDate is OpenApiDateTime removalDateValue) extension.RemovalDate = removalDateValue.Value; diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumFlagsExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumFlagsExtension.cs index e7dcf88f8..946537478 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumFlagsExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumFlagsExtension.cs @@ -45,7 +45,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiEnumFlagsExtension Parse(IOpenApiAny source) { - if (source is not OpenApiObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiObject rawObject) return null; var extension = new OpenApiEnumFlagsExtension(); if (rawObject.TryGetValue(nameof(IsFlags).ToFirstCharacterLowerCase(), out var flagsValue) && flagsValue is OpenApiBoolean isFlags) { diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs index 5c7c1ba31..272f4b313 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs @@ -64,7 +64,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiEnumValuesDescriptionExtension Parse(IOpenApiAny source) { - if (source is not OpenApiObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiObject rawObject) return null; var extension = new OpenApiEnumValuesDescriptionExtension(); if (rawObject.TryGetValue("values", out var values) && values is OpenApiArray valuesArray) { diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs index a73ecf005..9b81e2561 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs @@ -73,7 +73,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiPagingExtension Parse(IOpenApiAny source) { - if (source is not OpenApiObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiObject rawObject) return null; var extension = new OpenApiPagingExtension(); if (rawObject.TryGetValue(nameof(NextLinkName).ToFirstCharacterLowerCase(), out var nextLinkName) && nextLinkName is OpenApiString nextLinkNameStr) { diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs index fde7a54ea..0250af758 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs @@ -1,4 +1,4 @@ -// ------------------------------------------------------------ +// ------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ @@ -39,7 +39,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// The . public static OpenApiPrimaryErrorMessageExtension Parse(IOpenApiAny source) { - if (source is not OpenApiBoolean rawObject) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiBoolean rawObject) return null; return new() { IsPrimaryErrorMessage = rawObject.Value diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs index 77428e186..e45d9e7e9 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs @@ -41,7 +41,7 @@ public bool? IsReserved /// public static OpenApiReservedParameterExtension Parse(IOpenApiAny source) { - if (source is not OpenApiBoolean rawBoolean) throw new ArgumentOutOfRangeException(nameof(source)); + if (source is not OpenApiBoolean rawBoolean) return null; return new() { IsReserved = rawBoolean.Value From 858e85df86e5555bb3cb74e026f8b123f46fcb60 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:41:08 +0000 Subject: [PATCH 18/21] Bump docker/build-push-action from 6.0.0 to 6.1.0 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.0.0 to 6.1.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v6.0.0...v6.1.0) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d0c4264f2..27eb18d23 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,13 +30,13 @@ jobs: id: getversion - name: Push to GitHub Packages - Nightly if: ${{ github.ref == 'refs/heads/vnext' }} - uses: docker/build-push-action@v6.0.0 + uses: docker/build-push-action@v6.1.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly - name: Push to GitHub Packages - Release if: ${{ github.ref == 'refs/heads/master' }} - uses: docker/build-push-action@v6.0.0 + uses: docker/build-push-action@v6.1.0 with: push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }} From b3ddc2a68fac7aaa4f7af3a9273c23e48baa203e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:02:34 +0000 Subject: [PATCH 19/21] Bump Verify.Xunit from 25.0.3 to 25.0.4 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 25.0.3 to 25.0.4. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/25.0.3...25.0.4) --- 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 ab7ef80f3..351a72df4 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -15,7 +15,7 @@ - + From 84e7680c8b87f09787ee3da2986a278a0cd64f6d Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Wed, 26 Jun 2024 12:52:08 +0300 Subject: [PATCH 20/21] Add test to validate --- .../OpenApiReservedParameterExtensionTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiReservedParameterExtensionTests.cs b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiReservedParameterExtensionTests.cs index ca7870bc0..0ebeea11a 100644 --- a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiReservedParameterExtensionTests.cs +++ b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiReservedParameterExtensionTests.cs @@ -17,6 +17,19 @@ public void Parses() Assert.NotNull(value); Assert.True(value.IsReserved); } + + [Fact] + public void DoesNotThrowExceptionIfValueIsNull() + { + var oaiValue = new OpenApiObject + { + ["foo"] = new OpenApiString("foo") + }; + + var value = OpenApiReservedParameterExtension.Parse(oaiValue); + Assert.Null(value); + } + [Fact] public void Serializes() { From 4fe58269277ee939775ec98e0ffa7b5706c958bc Mon Sep 17 00:00:00 2001 From: Irvine Sunday <40403681+irvinesunday@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:49:21 +0300 Subject: [PATCH 21/21] Update conversion library version (#1702) --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 01e5c1427..7162a07e9 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -9,7 +9,7 @@ enable hidi ./../../artifacts - 1.4.5 + 1.4.6 OpenAPI.NET CLI tool for slicing OpenAPI documents true @@ -35,7 +35,7 @@ - +