@@ -13,6 +13,17 @@ namespace Microsoft.OpenApi.Any
13
13
/// </summary>
14
14
public class OpenApiExtensionDictionary : Dictionary < string , IOpenApiExtension >
15
15
{
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
+
16
27
/// <summary>
17
28
/// Override the base class indexer to return OpenApiAny.
18
29
/// </summary>
@@ -21,7 +32,7 @@ public class OpenApiExtensionDictionary : Dictionary<string, IOpenApiExtension>
21
32
public new OpenApiAny this [ string key ]
22
33
{
23
34
get => ( OpenApiAny ) base [ key ] ;
24
- set => base [ key ] = ConvertIfJsonNode ( value ) ;
35
+ set => base [ key ] = ConvertIfJsonNode ( value ) ! ;
25
36
}
26
37
27
38
/// <summary>
@@ -31,35 +42,17 @@ public class OpenApiExtensionDictionary : Dictionary<string, IOpenApiExtension>
31
42
/// <param name="value"></param>
32
43
public void Add ( string key , object value )
33
44
{
34
- base . Add ( key , ConvertIfJsonNode ( value ) ) ;
45
+ base . Add ( key , ConvertIfJsonNode ( value ) ! ) ;
35
46
}
36
47
37
- private static IOpenApiExtension ConvertIfJsonNode ( object ? value )
48
+ private static IOpenApiExtension ? ConvertIfJsonNode ( object ? value )
38
49
{
39
50
return value switch
40
51
{
41
52
IOpenApiExtension extension => extension ,
42
53
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
61
55
} ;
62
- extensions2 . Add ( "x-key" , ( OpenApiAny ) jsonNode ) ;
63
56
}
64
57
}
65
58
}
0 commit comments