From 011e72caadb488d4fe4d289d566f54691631ff73 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 20 Dec 2024 10:47:04 -0500 Subject: [PATCH 1/8] fix: reverts to a regular variable for the tag value Signed-off-by: Vincent Biret --- .azure-pipelines/ci-build.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index 5c07e63ee..d59d69cd3 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -297,10 +297,9 @@ extends: $artifactName = Get-ChildItem -Path $(Pipeline.Workspace)\Nugets -Filter Microsoft.OpenApi.*.nupkg -recurse | select -First 1 $artifactVersion= $artifactName.Name -replace "Microsoft.OpenApi.", "" -replace ".nupkg", "" #Set Variable $artifactName and $artifactVersion - Write-Host "##vso[task.setvariable variable=artifactVersion; isSecret=false; isOutput=true]$artifactVersion" + Write-Host "##vso[task.setvariable variable=artifactVersion; isSecret=false;]$artifactVersion" echo "$artifactVersion" displayName: 'Fetch Artifact Name' - name: getTagVersion - task: GitHubRelease@1 displayName: 'GitHub release (edit)' condition: succeededOrFailed() @@ -308,8 +307,8 @@ extends: gitHubConnection: 'Github-MaggieKimani1' action: create tagSource: userSpecifiedTag - tag: '$(getTagVersion.artifactVersion)' - title: '$(getTagVersion.artifactVersion)' + tag: '$(artifactVersion)' + title: '$(artifactVersion)' releaseNotesSource: inline assets: '$(Pipeline.Workspace)\**\*.exe' changeLogType: issueBased From e7c9e1bbdbdb29bc1b7680f86994138bfac42cbd Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 20 Dec 2024 10:55:27 -0500 Subject: [PATCH 2/8] ci: fix artefacts path --- .azure-pipelines/ci-build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index d59d69cd3..6686bba75 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -216,7 +216,7 @@ extends: - task: 1ES.PublishNuget@1 displayName: 'NuGet push' inputs: - packagesToPush: '$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Hidi.*.nupkg' + packagesToPush: '$(Pipeline.Workspace)/Microsoft.OpenApi.Hidi.*.nupkg' packageParentPath: '$(Pipeline.Workspace)' nuGetFeedType: external publishFeedCredentials: 'OpenAPI Nuget Connection' @@ -238,7 +238,7 @@ extends: vmImage: ubuntu-latest steps: - powershell: | - $fileNames = "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Hidi.*.nupkg", "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Readers.*.nupkg", "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Workbench.*.nupkg" + $fileNames = "$(Pipeline.Workspace)/Microsoft.OpenApi.Hidi.*.nupkg", "$(Pipeline.Workspace)/Microsoft.OpenApi.Readers.*.nupkg", "$(Pipeline.Workspace)/Microsoft.OpenApi.Workbench.*.nupkg" foreach($fileName in $fileNames) { if(Test-Path $fileName) { rm $fileName -Verbose @@ -248,7 +248,7 @@ extends: - task: 1ES.PublishNuget@1 displayName: 'NuGet push' inputs: - packagesToPush: '$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.*.nupkg' + packagesToPush: '$(Pipeline.Workspace)/Microsoft.OpenApi.*.nupkg' packageParentPath: '$(Pipeline.Workspace)' nuGetFeedType: external publishFeedCredentials: 'OpenAPI Nuget Connection' @@ -272,7 +272,7 @@ extends: - task: 1ES.PublishNuget@1 displayName: 'NuGet push' inputs: - packagesToPush: '$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Readers.*.nupkg' + packagesToPush: '$(Pipeline.Workspace)/Microsoft.OpenApi.Readers.*.nupkg' packageParentPath: '$(Pipeline.Workspace)' nuGetFeedType: external publishFeedCredentials: 'OpenAPI Nuget Connection' @@ -294,7 +294,7 @@ extends: vmImage: ubuntu-latest steps: - pwsh: | - $artifactName = Get-ChildItem -Path $(Pipeline.Workspace)\Nugets -Filter Microsoft.OpenApi.*.nupkg -recurse | select -First 1 + $artifactName = Get-ChildItem -Path $(Pipeline.Workspace) -Filter Microsoft.OpenApi.*.nupkg -recurse | select -First 1 $artifactVersion= $artifactName.Name -replace "Microsoft.OpenApi.", "" -replace ".nupkg", "" #Set Variable $artifactName and $artifactVersion Write-Host "##vso[task.setvariable variable=artifactVersion; isSecret=false;]$artifactVersion" From e29e24c58f51af4f6a39aeb65041dbd7f7ab888f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 23 Dec 2024 10:34:28 -0500 Subject: [PATCH 3/8] fix: enum description number values Signed-off-by: Vincent Biret --- .../OpenApiEnumValuesDescriptionExtension.cs | 7 ++- ...nApiEnumValuesDescriptionExtensionTests.cs | 55 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs index 1235e68b0..a6df2444b 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs @@ -11,6 +11,8 @@ using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; using System.Text.Json.Nodes; +using System.Text.Json; +using System.Globalization; namespace Microsoft.OpenApi.MicrosoftExtensions; @@ -97,7 +99,10 @@ public EnumDescription(JsonObject source) { if (source is null) throw new ArgumentNullException(nameof(source)); if (source.TryGetPropertyValue(nameof(Value).ToFirstCharacterLowerCase(), out var rawValue) && rawValue is JsonNode value) - Value = value.GetValue(); + if (value.GetValueKind() == JsonValueKind.Number) + Value = value.GetValue().ToString(CultureInfo.InvariantCulture); + else + Value = value.GetValue(); if (source.TryGetPropertyValue(nameof(Description).ToFirstCharacterLowerCase(), out var rawDescription) && rawDescription is JsonNode description) Description = description.GetValue(); if (source.TryGetPropertyValue(nameof(Name).ToFirstCharacterLowerCase(), out var rawName) && rawName is JsonNode name) diff --git a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtensionTests.cs b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtensionTests.cs index 3b9f9964a..f09e07657 100644 --- a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtensionTests.cs +++ b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtensionTests.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Text.Json.Nodes; using Microsoft.OpenApi.MicrosoftExtensions; using Microsoft.OpenApi.Writers; using Xunit; @@ -22,7 +23,7 @@ public void WritesNothingWhenNoValues() { // Arrange OpenApiEnumValuesDescriptionExtension extension = new(); - using TextWriter sWriter = new StringWriter(); + using var sWriter = new StringWriter(); OpenApiJsonWriter writer = new(sWriter); // Act @@ -41,16 +42,16 @@ public void WritesEnumDescription() OpenApiEnumValuesDescriptionExtension extension = new() { EnumName = "TestEnum", - ValuesDescriptions = new() - { + ValuesDescriptions = + [ new() { Description = "TestDescription", Value = "TestValue", Name = "TestName" } - } + ] }; - using TextWriter sWriter = new StringWriter(); + using var sWriter = new StringWriter(); OpenApiJsonWriter writer = new(sWriter); // Act @@ -65,5 +66,49 @@ public void WritesEnumDescription() Assert.Contains("value\": \"TestValue", result); Assert.Contains("name\": \"TestName", result); } + [Fact] + public void ParsesEnumDescription() + { + var extensionValue = +""" +{ + "value": "Standard_LRS", + "description": "Locally redundant storage.", + "name": "StandardLocalRedundancy" +} +"""; + var source = JsonNode.Parse(extensionValue); + Assert.NotNull(source); + var sourceAsObject = source.AsObject(); + Assert.NotNull(sourceAsObject); + + var descriptionItem = new EnumDescription(sourceAsObject); + Assert.NotNull(descriptionItem); + Assert.Equal("Standard_LRS", descriptionItem.Value); + Assert.Equal("Locally redundant storage.", descriptionItem.Description); + Assert.Equal("StandardLocalRedundancy", descriptionItem.Name); + } + [Fact] + public void ParsesEnumDescriptionWithDecimalValue() + { + var extensionValue = +""" +{ + "value": -1, + "description": "Locally redundant storage.", + "name": "StandardLocalRedundancy" +} +"""; + var source = JsonNode.Parse(extensionValue); + Assert.NotNull(source); + var sourceAsObject = source.AsObject(); + Assert.NotNull(sourceAsObject); + + var descriptionItem = new EnumDescription(sourceAsObject); + Assert.NotNull(descriptionItem); + Assert.Equal("-1", descriptionItem.Value); + Assert.Equal("Locally redundant storage.", descriptionItem.Description); + Assert.Equal("StandardLocalRedundancy", descriptionItem.Name); + } } From d8c159331c230154236faafc315d008c61f3eb7b Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 23 Dec 2024 12:35:34 -0500 Subject: [PATCH 4/8] feat: adds deconstructor to read result --- src/Microsoft.OpenApi/Reader/ReadResult.cs | 8 ++++++++ .../PublicApi/PublicApi.approved.txt | 1 + 2 files changed, 9 insertions(+) diff --git a/src/Microsoft.OpenApi/Reader/ReadResult.cs b/src/Microsoft.OpenApi/Reader/ReadResult.cs index a0013b249..aa835478a 100644 --- a/src/Microsoft.OpenApi/Reader/ReadResult.cs +++ b/src/Microsoft.OpenApi/Reader/ReadResult.cs @@ -18,5 +18,13 @@ public class ReadResult /// OpenApiDiagnostic contains the Errors reported while parsing /// public OpenApiDiagnostic Diagnostic { get; set; } + /// + /// Deconstructs the result for easier assignment on the client application. + /// + public void Deconstruct(out OpenApiDocument document, out OpenApiDiagnostic diagnostic) + { + document = Document; + diagnostic = Diagnostic; + } } } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index a3681e9d5..642dd0b82 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1380,6 +1380,7 @@ namespace Microsoft.OpenApi.Reader public ReadResult() { } public Microsoft.OpenApi.Reader.OpenApiDiagnostic Diagnostic { get; set; } public Microsoft.OpenApi.Models.OpenApiDocument Document { get; set; } + public void Deconstruct(out Microsoft.OpenApi.Models.OpenApiDocument document, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic) { } } public enum ReferenceResolutionSetting { From 8902656681487c22451c08cdc3b4e4aef41db9be Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 23 Dec 2024 12:38:41 -0500 Subject: [PATCH 5/8] chore: adds test for deconstructor Signed-off-by: Vincent Biret --- .../Reader/ReadResultTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs diff --git a/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs b/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs new file mode 100644 index 000000000..c3a87c7a3 --- /dev/null +++ b/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs @@ -0,0 +1,21 @@ +using Xunit; +using Microsoft.OpenApi.Reader; +using Microsoft.OpenApi.Models; + +namespace Microsoft.OpenApi.Tests.Reader; + +public class ReadResultTests +{ + [Fact] + public void Deconstructs() + { + var readResult = new ReadResult() + { + Document = new OpenApiDocument(), + Diagnostic = new OpenApiDiagnostic() + }; + var (document, diagnostic) = readResult; + Assert.Equal(readResult.Document, document); + Assert.Equal(readResult.Diagnostic, diagnostic); + } +} From da6396c725516a8375110a70f74507d4a5b7698e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:38:16 +0000 Subject: [PATCH 6/8] chore(deps): bump Verify.Xunit from 28.6.1 to 28.7.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 28.6.1 to 28.7.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/28.6.1...28.7.0) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... 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 59f05da32..634c70257 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -14,7 +14,7 @@ - + From cd13481f4e3a883186d10b3af63cbd928a17c8ba Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 24 Dec 2024 08:18:48 -0500 Subject: [PATCH 7/8] fix: specifies encoding for net fx Signed-off-by: Vincent Biret --- .../Microsoft.OpenApi.Readers.csproj | 3 ++- src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 05e3e52e6..68ff691bf 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -1,6 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0; + latest true 2.0.0-preview3 diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs index 95e58c52f..217db91b3 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs @@ -12,6 +12,7 @@ using System.Linq; using Microsoft.OpenApi.Models; using System; +using System.Text; namespace Microsoft.OpenApi.Readers { @@ -53,7 +54,13 @@ public ReadResult Read(MemoryStream input, // Parse the YAML text in the stream into a sequence of JsonNodes try { +#if NET +// this represents net core, net5 and up using var stream = new StreamReader(input, default, true, -1, settings.LeaveStreamOpen); +#else +// the implementation differs and results in a null reference exception in NETFX + using var stream = new StreamReader(input, Encoding.UTF8, true, 4096, settings.LeaveStreamOpen); +#endif jsonNode = LoadJsonNodesFromYamlDocument(stream); } catch (JsonException ex) From 17649dcd59814bcbfe444d45f242c3516d40d5f4 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 24 Dec 2024 08:45:58 -0500 Subject: [PATCH 8/8] chore: bumps preview version --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 04c42ee47..52672405e 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 - 2.0.0-preview3 + 2.0.0-preview4 OpenAPI.NET CLI tool for slicing OpenAPI documents true diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 05e3e52e6..44e4047bb 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 - 2.0.0-preview3 + 2.0.0-preview4 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 5c4e18a29..e0b815f5d 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -3,7 +3,7 @@ netstandard2.0 Latest true - 2.0.0-preview3 + 2.0.0-preview4 .NET models with JSON and YAML writers for OpenAPI specification true