33using System . Globalization ;
44using System . Linq ;
55using System . Text . Json . Nodes ;
6- using SharpYaml ;
7- using SharpYaml . Serialization ;
6+ using YamlDotNet . RepresentationModel ;
7+ using YamlDotNet . Core ;
88
99namespace 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 )
0 commit comments