Skip to content

Commit 4ac5a1b

Browse files
Copilotbaywet
andcommitted
Successfully replace SharpYaml dependency with YamlDotNet
Co-authored-by: baywet <[email protected]>
1 parent 4b18cff commit 4ac5a1b

File tree

13 files changed

+22
-20
lines changed

13 files changed

+22
-20
lines changed

src/Microsoft.OpenApi.YamlReader/Microsoft.OpenApi.YamlReader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PrivateAssets>all</PrivateAssets>
3434
</PackageReference>
3535

36-
<PackageReference Include="SharpYaml" Version="2.1.2" />
36+
<PackageReference Include="YamlDotNet" Version="16.3.0" />
3737
<PackageReference Include="System.Text.Json" Version="[8.0.5,)" />
3838
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-hh2w-p6rv-4g7w" />
3939
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-8g4q-xg66-9fp4" />

src/Microsoft.OpenApi.YamlReader/OpenApiYamlReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Microsoft.OpenApi.Reader;
10-
using SharpYaml.Serialization;
10+
using YamlDotNet.RepresentationModel;
1111
using System;
1212
using System.Linq;
1313
using System.Text;

src/Microsoft.OpenApi.YamlReader/YamlConverter.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using System.Globalization;
44
using System.Linq;
55
using System.Text.Json.Nodes;
6-
using SharpYaml;
7-
using SharpYaml.Serialization;
6+
using YamlDotNet.RepresentationModel;
7+
using YamlDotNet.Core;
88

99
namespace Microsoft.OpenApi.YamlReader
1010
{
@@ -75,7 +75,7 @@ public static YamlNode ToYamlNode(this JsonNode json)
7575
public static JsonObject ToJsonObject(this YamlMappingNode yaml)
7676
{
7777
var node = new JsonObject();
78-
foreach (var keyValuePair in yaml)
78+
foreach (var keyValuePair in yaml.Children)
7979
{
8080
var key = ((YamlScalarNode)keyValuePair.Key).Value!;
8181
node[key] = keyValuePair.Value.ToJsonNode();
@@ -86,7 +86,8 @@ public static JsonObject ToJsonObject(this YamlMappingNode yaml)
8686

8787
private static YamlMappingNode ToYamlMapping(this JsonObject obj)
8888
{
89-
return new YamlMappingNode(obj.ToDictionary(x => (YamlNode)new YamlScalarNode(x.Key), x => x.Value!.ToYamlNode()));
89+
var children = obj.ToDictionary(x => (YamlNode)new YamlScalarNode(x.Key), x => x.Value!.ToYamlNode());
90+
return new YamlMappingNode(children);
9091
}
9192

9293
/// <summary>
@@ -97,7 +98,7 @@ private static YamlMappingNode ToYamlMapping(this JsonObject obj)
9798
public static JsonArray ToJsonArray(this YamlSequenceNode yaml)
9899
{
99100
var node = new JsonArray();
100-
foreach (var value in yaml)
101+
foreach (var value in yaml.Children)
101102
{
102103
node.Add(value.ToJsonNode());
103104
}
@@ -107,7 +108,8 @@ public static JsonArray ToJsonArray(this YamlSequenceNode yaml)
107108

108109
private static YamlSequenceNode ToYamlSequence(this JsonArray arr)
109110
{
110-
return new YamlSequenceNode(arr.Select(x => x!.ToYamlNode()));
111+
var children = arr.Select(x => x!.ToYamlNode()).ToList();
112+
return new YamlSequenceNode(children);
111113
}
112114

113115
private static JsonValue ToJsonValue(this YamlScalarNode yaml)

src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ internal void SetJsonPointerPath(string pointer, string nodeLocation)
316316
private static string ResolveRelativePointer(string nodeLocation, string relativeRef)
317317
{
318318
// Convert nodeLocation to path segments
319-
var segments = nodeLocation.TrimStart('#').Split(['/'], StringSplitOptions.RemoveEmptyEntries).ToList();
319+
var segments = nodeLocation.TrimStart('#').Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList();
320320

321321
// Convert relativeRef to dynamic segments
322-
var relativeSegments = relativeRef.TrimStart('#').Split(['/'], StringSplitOptions.RemoveEmptyEntries);
322+
var relativeSegments = relativeRef.TrimStart('#').Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
323323

324324
// Locate the first occurrence of relativeRef segments in the full path
325325
for (int i = 0; i <= segments.Count - relativeSegments.Length; i++)

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ private static string ConvertByteArrayToString(byte[] hash)
589589
// Enables setting the complete JSON path for nested subschemas e.g. #/components/schemas/person/properties/address
590590
if (useExternal)
591591
{
592-
var relPathSegment = referenceV3.Split(['#'], StringSplitOptions.RemoveEmptyEntries)[1];
592+
var relPathSegment = referenceV3.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries)[1];
593593
relativePath = $"#{relPathSegment}";
594594
}
595595
else
@@ -625,7 +625,7 @@ private static bool IsSubComponent(string reference)
625625

626626
if (fragment.StartsWith("/components/schemas/", StringComparison.OrdinalIgnoreCase))
627627
{
628-
var segments = fragment.Split(['/'], StringSplitOptions.RemoveEmptyEntries);
628+
var segments = fragment.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
629629

630630
// Expect exactly 3 segments for root-level schema: ["components", "schemas", "person"]
631631
// Anything longer means it's a subcomponent.

src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public bool Contains(string location)
347347

348348
if (uri is not null)
349349
{
350-
pathSegments = uri.Fragment.Split(['/'], StringSplitOptions.RemoveEmptyEntries);
350+
pathSegments = uri.Fragment.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
351351

352352
// Build the base path for the root schema: "#/components/schemas/person"
353353
var fragment = OpenApiConstants.ComponentsSegment + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + pathSegments[3];

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="coverlet.msbuild" Version="6.0.4" PrivateAssets="all" />
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
2121
<PackageReference Include="FluentAssertions" Version="7.2.0" />
22-
<PackageReference Include="SharpYaml" Version="2.1.2" />
22+
<PackageReference Include="YamlDotNet" Version="16.3.0" />
2323
<PackageReference Include="xunit" Version="2.9.3" />
2424
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1" PrivateAssets="all" />
2525
</ItemGroup>

test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.IO;
55
using Microsoft.OpenApi.Reader;
66
using Microsoft.OpenApi.YamlReader;
7-
using SharpYaml.Serialization;
7+
using YamlDotNet.RepresentationModel;
88

99
namespace Microsoft.OpenApi.Readers.Tests
1010
{

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.OpenApi.Reader;
88
using Microsoft.OpenApi.Reader.V2;
99
using Microsoft.OpenApi.YamlReader;
10-
using SharpYaml.Serialization;
10+
using YamlDotNet.RepresentationModel;
1111
using Xunit;
1212

1313
namespace Microsoft.OpenApi.Readers.Tests.V2Tests

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiInfoTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.OpenApi.Reader;
44
using Microsoft.OpenApi.Reader.V31;
55
using Microsoft.OpenApi.YamlReader;
6-
using SharpYaml.Serialization;
6+
using YamlDotNet.RepresentationModel;
77
using Xunit;
88

99
namespace Microsoft.OpenApi.Readers.Tests.V31Tests

0 commit comments

Comments
 (0)