File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
src/Microsoft.OpenApi.YamlReader
test/Microsoft.OpenApi.Readers.Tests Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ public static YamlNode ToYamlNode(this JsonNode json)
6363 {
6464 JsonObject obj => obj . ToYamlMapping ( ) ,
6565 JsonArray arr => arr . ToYamlSequence ( ) ,
66+ JsonValue nullVal when JsonNullSentinel . IsJsonNullSentinel ( nullVal ) => new YamlScalarNode ( "null" )
67+ {
68+ Style = ScalarStyle . Plain
69+ } ,
6670 JsonValue val => val . ToYamlScalar ( ) ,
6771 _ => throw new NotSupportedException ( "This isn't a supported JsonNode" )
6872 } ;
Original file line number Diff line number Diff line change 22using Microsoft . OpenApi . YamlReader ;
33using SharpYaml ;
44using SharpYaml . Serialization ;
5+ using System ;
56using System . IO ;
67using System . Text . Json . Nodes ;
78using Xunit ;
@@ -302,10 +303,18 @@ from openai import OpenAI
302303 var jsonNode = ConvertYamlStringToJsonNode ( yamlInput ) ;
303304 var convertedBack = jsonNode . ToYamlNode ( ) ;
304305 var convertedBackOutput = ConvertYamlNodeToString ( convertedBack ) ;
305-
306+
306307 // Then
307308 Assert . Equal ( yamlInput . MakeLineBreaksEnvironmentNeutral ( ) , convertedBackOutput . MakeLineBreaksEnvironmentNeutral ( ) ) ;
308309 }
310+ [ Fact ]
311+ public void ItDoesNotSerializeTheSentinelValue ( )
312+ {
313+ var yamlValue = JsonNullSentinel . JsonNull . ToYamlNode ( ) ;
314+
315+ var scalarNode = Assert . IsType < YamlScalarNode > ( yamlValue ) ;
316+ Assert . Equal ( "null" , scalarNode . Value , StringComparer . OrdinalIgnoreCase ) ;
317+ }
309318
310319 private static JsonNode ConvertYamlStringToJsonNode ( string yamlInput )
311320 {
You can’t perform that action at this time.
0 commit comments