File tree Expand file tree Collapse file tree 5 files changed +22
-12
lines changed Expand file tree Collapse file tree 5 files changed +22
-12
lines changed Original file line number Diff line number Diff line change 2
2
// Licensed under the MIT license.
3
3
4
4
using System . Text . Json ;
5
+ using System . Text . Json . Nodes ;
5
6
using System . Text . Json . Serialization ;
6
7
using Json . Schema ;
7
8
using Microsoft . OpenApi . Any ;
@@ -17,15 +18,24 @@ internal static class JsonNodeCloneHelper
17
18
18
19
internal static OpenApiAny Clone ( OpenApiAny value )
19
20
{
20
- var jsonString = Serialize ( value ) ;
21
- var result = JsonSerializer . Deserialize < OpenApiAny > ( jsonString , options ) ;
21
+ var jsonString = Serialize ( value ? . Node ) ;
22
+ if ( string . IsNullOrEmpty ( jsonString ) )
23
+ {
24
+ return null ;
25
+ }
22
26
23
- return result ;
27
+ var result = JsonSerializer . Deserialize < JsonNode > ( jsonString , options ) ;
28
+ return new OpenApiAny ( result ) ;
24
29
}
25
30
26
31
internal static JsonSchema CloneJsonSchema ( JsonSchema schema )
27
32
{
28
33
var jsonString = Serialize ( schema ) ;
34
+ if ( string . IsNullOrEmpty ( jsonString ) )
35
+ {
36
+ return null ;
37
+ }
38
+
29
39
var result = JsonSerializer . Deserialize < JsonSchema > ( jsonString , options ) ;
30
40
return result ;
31
41
}
Original file line number Diff line number Diff line change @@ -68,10 +68,10 @@ public OpenApiExample(OpenApiExample example)
68
68
{
69
69
Summary = example ? . Summary ?? Summary ;
70
70
Description = example ? . Description ?? Description ;
71
- Value = example ? . Value ?? JsonNodeCloneHelper . Clone ( example ? . Value ) ;
71
+ Value = example ? . Value != null ? JsonNodeCloneHelper . Clone ( example . Value ) : null ;
72
72
ExternalValue = example ? . ExternalValue ?? ExternalValue ;
73
73
Extensions = example ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( example . Extensions ) : null ;
74
- Reference = example ? . Reference != null ? new ( example ? . Reference ) : null ;
74
+ Reference = example ? . Reference != null ? new ( example . Reference ) : null ;
75
75
UnresolvedReference = example ? . UnresolvedReference ?? UnresolvedReference ;
76
76
}
77
77
Original file line number Diff line number Diff line change @@ -114,8 +114,8 @@ public OpenApiHeader(OpenApiHeader header)
114
114
Style = header ? . Style ?? Style ;
115
115
Explode = header ? . Explode ?? Explode ;
116
116
AllowReserved = header ? . AllowReserved ?? AllowReserved ;
117
- Schema = header ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( header ? . Schema ) : null ;
118
- Example = header ? . Example != null ? JsonNodeCloneHelper . Clone ( header ? . Example ) : null ;
117
+ Schema = header ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( header . Schema ) : null ;
118
+ Example = header ? . Example != null ? JsonNodeCloneHelper . Clone ( header . Example ) : null ;
119
119
Examples = header ? . Examples != null ? new Dictionary < string , OpenApiExample > ( header . Examples ) : null ;
120
120
Content = header ? . Content != null ? new Dictionary < string , OpenApiMediaType > ( header . Content ) : null ;
121
121
Extensions = header ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( header . Extensions ) : null ;
Original file line number Diff line number Diff line change @@ -62,8 +62,8 @@ public OpenApiMediaType() { }
62
62
/// </summary>
63
63
public OpenApiMediaType ( OpenApiMediaType mediaType )
64
64
{
65
- _schema = JsonNodeCloneHelper . CloneJsonSchema ( mediaType ? . Schema ) ;
66
- Example = JsonNodeCloneHelper . Clone ( mediaType ? . Example ) ;
65
+ Schema = mediaType ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( mediaType . Schema ) : null ;
66
+ Example = mediaType ? . Example != null ? JsonNodeCloneHelper . Clone ( mediaType . Example ) : null ;
67
67
Examples = mediaType ? . Examples != null ? new Dictionary < string , OpenApiExample > ( mediaType . Examples ) : null ;
68
68
Encoding = mediaType ? . Encoding != null ? new Dictionary < string , OpenApiEncoding > ( mediaType . Encoding ) : null ;
69
69
Extensions = mediaType ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( mediaType . Extensions ) : null ;
Original file line number Diff line number Diff line change 1
- // Copyright (c) Microsoft Corporation. All rights reserved.
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
4
using System ;
@@ -168,9 +168,9 @@ public OpenApiParameter(OpenApiParameter parameter)
168
168
Style = parameter ? . Style ?? Style ;
169
169
Explode = parameter ? . Explode ?? Explode ;
170
170
AllowReserved = parameter ? . AllowReserved ?? AllowReserved ;
171
- Schema = parameter ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( parameter ? . Schema ) : null ;
171
+ Schema = parameter ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( parameter . Schema ) : null ;
172
172
Examples = parameter ? . Examples != null ? new Dictionary < string , OpenApiExample > ( parameter . Examples ) : null ;
173
- Example = parameter ? . Example != null ? JsonNodeCloneHelper . Clone ( parameter ? . Example ) : null ;
173
+ Example = parameter ? . Example != null ? JsonNodeCloneHelper . Clone ( parameter . Example ) : null ;
174
174
Content = parameter ? . Content != null ? new Dictionary < string , OpenApiMediaType > ( parameter . Content ) : null ;
175
175
Extensions = parameter ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( parameter . Extensions ) : null ;
176
176
AllowEmptyValue = parameter ? . AllowEmptyValue ?? AllowEmptyValue ;
You can’t perform that action at this time.
0 commit comments