Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #2028

Merged
merged 14 commits into from
Dec 24, 2024
Merged

dev #2028

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -294,22 +294,21 @@ 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; 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()
inputs:
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
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>2.0.0-preview3</Version>
<Version>2.0.0-preview4</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview3</Version>
<Version>2.0.0-preview4</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using Microsoft.OpenApi.Models;
using System;
using System.Text;

namespace Microsoft.OpenApi.Readers
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview3</Version>
<Version>2.0.0-preview4</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -97,7 +99,10 @@
{
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<string>();
if (value.GetValueKind() == JsonValueKind.Number)
Value = value.GetValue<decimal>().ToString(CultureInfo.InvariantCulture);
else
Value = value.GetValue<string>();
Comment on lines +102 to +105

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.
if (source.TryGetPropertyValue(nameof(Description).ToFirstCharacterLowerCase(), out var rawDescription) && rawDescription is JsonNode description)
Description = description.GetValue<string>();
if (source.TryGetPropertyValue(nameof(Name).ToFirstCharacterLowerCase(), out var rawName) && rawName is JsonNode name)
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.OpenApi/Reader/ReadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ public class ReadResult
/// OpenApiDiagnostic contains the Errors reported while parsing
/// </summary>
public OpenApiDiagnostic Diagnostic { get; set; }
/// <summary>
/// Deconstructs the result for easier assignment on the client application.
/// </summary>
public void Deconstruct(out OpenApiDocument document, out OpenApiDiagnostic diagnostic)
{
document = Document;
diagnostic = Diagnostic;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="Verify.Xunit" Version="28.6.1" />
<PackageReference Include="Verify.Xunit" Version="28.7.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.MicrosoftExtensions;
using Microsoft.OpenApi.Writers;
using Xunit;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
21 changes: 21 additions & 0 deletions test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading