Skip to content
Merged
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
fix: a bug where null sentinel value would appear in YAML documents
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Nov 6, 2025
commit 15618e1f6a79874ae61dc31e3bcd5e1f3177d7ff
4 changes: 4 additions & 0 deletions src/Microsoft.OpenApi.YamlReader/YamlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static YamlNode ToYamlNode(this JsonNode json)
{
JsonObject obj => obj.ToYamlMapping(),
JsonArray arr => arr.ToYamlSequence(),
JsonValue nullVal when JsonNullSentinel.IsJsonNullSentinel(nullVal) => new YamlScalarNode("null")
{
Style = ScalarStyle.Plain
},
JsonValue val => val.ToYamlScalar(),
_ => throw new NotSupportedException("This isn't a supported JsonNode")
};
Expand Down
11 changes: 10 additions & 1 deletion test/Microsoft.OpenApi.Readers.Tests/YamlConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.OpenApi.YamlReader;
using SharpYaml;
using SharpYaml.Serialization;
using System;
using System.IO;
using System.Text.Json.Nodes;
using Xunit;
Expand Down Expand Up @@ -302,10 +303,18 @@ from openai import OpenAI
var jsonNode = ConvertYamlStringToJsonNode(yamlInput);
var convertedBack = jsonNode.ToYamlNode();
var convertedBackOutput = ConvertYamlNodeToString(convertedBack);

// Then
Assert.Equal(yamlInput.MakeLineBreaksEnvironmentNeutral(), convertedBackOutput.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public void ItDoesNotSerializeTheSentinelValue()
{
var yamlValue = JsonNullSentinel.JsonNull.ToYamlNode();

var scalarNode = Assert.IsType<YamlScalarNode>(yamlValue);
Assert.Equal("null", scalarNode.Value, StringComparer.OrdinalIgnoreCase);
}

private static JsonNode ConvertYamlStringToJsonNode(string yamlInput)
{
Expand Down
Loading