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 22// Licensed under the MIT license.
33
44using System . Text . Json ;
5+ using System . Text . Json . Nodes ;
56using System . Text . Json . Serialization ;
67using Json . Schema ;
78using Microsoft . OpenApi . Any ;
@@ -17,15 +18,24 @@ internal static class JsonNodeCloneHelper
1718
1819 internal static OpenApiAny Clone ( OpenApiAny value )
1920 {
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+ }
2226
23- return result ;
27+ var result = JsonSerializer . Deserialize < JsonNode > ( jsonString , options ) ;
28+ return new OpenApiAny ( result ) ;
2429 }
2530
2631 internal static JsonSchema CloneJsonSchema ( JsonSchema schema )
2732 {
2833 var jsonString = Serialize ( schema ) ;
34+ if ( string . IsNullOrEmpty ( jsonString ) )
35+ {
36+ return null ;
37+ }
38+
2939 var result = JsonSerializer . Deserialize < JsonSchema > ( jsonString , options ) ;
3040 return result ;
3141 }
Original file line number Diff line number Diff line change @@ -68,10 +68,10 @@ public OpenApiExample(OpenApiExample example)
6868 {
6969 Summary = example ? . Summary ?? Summary ;
7070 Description = example ? . Description ?? Description ;
71- Value = example ? . Value ?? JsonNodeCloneHelper . Clone ( example ? . Value ) ;
71+ Value = example ? . Value != null ? JsonNodeCloneHelper . Clone ( example . Value ) : null ;
7272 ExternalValue = example ? . ExternalValue ?? ExternalValue ;
7373 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 ;
7575 UnresolvedReference = example ? . UnresolvedReference ?? UnresolvedReference ;
7676 }
7777
Original file line number Diff line number Diff line change @@ -114,8 +114,8 @@ public OpenApiHeader(OpenApiHeader header)
114114 Style = header ? . Style ?? Style ;
115115 Explode = header ? . Explode ?? Explode ;
116116 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 ;
119119 Examples = header ? . Examples != null ? new Dictionary < string , OpenApiExample > ( header . Examples ) : null ;
120120 Content = header ? . Content != null ? new Dictionary < string , OpenApiMediaType > ( header . Content ) : null ;
121121 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() { }
6262 /// </summary>
6363 public OpenApiMediaType ( OpenApiMediaType mediaType )
6464 {
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 ;
6767 Examples = mediaType ? . Examples != null ? new Dictionary < string , OpenApiExample > ( mediaType . Examples ) : null ;
6868 Encoding = mediaType ? . Encoding != null ? new Dictionary < string , OpenApiEncoding > ( mediaType . Encoding ) : null ;
6969 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.
22// Licensed under the MIT license.
33
44using System ;
@@ -168,9 +168,9 @@ public OpenApiParameter(OpenApiParameter parameter)
168168 Style = parameter ? . Style ?? Style ;
169169 Explode = parameter ? . Explode ?? Explode ;
170170 AllowReserved = parameter ? . AllowReserved ?? AllowReserved ;
171- Schema = parameter ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( parameter ? . Schema ) : null ;
171+ Schema = parameter ? . Schema != null ? JsonNodeCloneHelper . CloneJsonSchema ( parameter . Schema ) : null ;
172172 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 ;
174174 Content = parameter ? . Content != null ? new Dictionary < string , OpenApiMediaType > ( parameter . Content ) : null ;
175175 Extensions = parameter ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( parameter . Extensions ) : null ;
176176 AllowEmptyValue = parameter ? . AllowEmptyValue ?? AllowEmptyValue ;
You can’t perform that action at this time.
0 commit comments