@@ -13,6 +13,17 @@ namespace Microsoft.OpenApi.Any
1313 /// </summary>
1414 public class OpenApiExtensionDictionary : Dictionary < string , IOpenApiExtension >
1515 {
16+ /// <summary>
17+ /// Initializes a copy of <see cref="OpenApiExtensionDictionary"/> object
18+ /// </summary>
19+ /// <param name="extensions"></param>
20+ public OpenApiExtensionDictionary ( OpenApiExtensionDictionary extensions ) : base ( dictionary : extensions ) { }
21+
22+ /// <summary>
23+ /// Parameterless constructor
24+ /// </summary>
25+ public OpenApiExtensionDictionary ( ) { }
26+
1627 /// <summary>
1728 /// Override the base class indexer to return OpenApiAny.
1829 /// </summary>
@@ -21,7 +32,7 @@ public class OpenApiExtensionDictionary : Dictionary<string, IOpenApiExtension>
2132 public new OpenApiAny this [ string key ]
2233 {
2334 get => ( OpenApiAny ) base [ key ] ;
24- set => base [ key ] = ConvertIfJsonNode ( value ) ;
35+ set => base [ key ] = ConvertIfJsonNode ( value ) ! ;
2536 }
2637
2738 /// <summary>
@@ -31,35 +42,17 @@ public class OpenApiExtensionDictionary : Dictionary<string, IOpenApiExtension>
3142 /// <param name="value"></param>
3243 public void Add ( string key , object value )
3344 {
34- base . Add ( key , ConvertIfJsonNode ( value ) ) ;
45+ base . Add ( key , ConvertIfJsonNode ( value ) ! ) ;
3546 }
3647
37- private static IOpenApiExtension ConvertIfJsonNode ( object ? value )
48+ private static IOpenApiExtension ? ConvertIfJsonNode ( object ? value )
3849 {
3950 return value switch
4051 {
4152 IOpenApiExtension extension => extension ,
4253 JsonNode node => ( OpenApiAny ) node ,
43- _ => throw new InvalidOperationException ( $ "Cannot convert value of type '{ value ? . GetType ( ) . Name } ' to IOpenApiExtension.")
44- } ;
45- }
46-
47- /// <summary>
48- /// Test the OpenApiExtensionDictionary and base class implementations.
49- /// </summary>
50- public static void TestExtensions ( )
51- {
52- var jsonNode = new JsonObject ( ) ;
53- var extensions = new OpenApiExtensionDictionary
54- {
55- [ "x-key" ] = jsonNode
56- } ;
57- extensions . Add ( "x-key" , jsonNode ) ;
58- var extensions2 = new Dictionary < string , IOpenApiExtension >
59- {
60- [ "x-key" ] = ( OpenApiAny ) jsonNode
54+ _ => null
6155 } ;
62- extensions2 . Add ( "x-key" , ( OpenApiAny ) jsonNode ) ;
6356 }
6457 }
6558}
0 commit comments