5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using System . Text . Json . Nodes ;
8
- using Microsoft . OpenApi . Any ;
9
8
using Microsoft . OpenApi . Helpers ;
10
9
using Microsoft . OpenApi . Interfaces ;
11
10
using Microsoft . OpenApi . Writers ;
@@ -17,6 +16,10 @@ namespace Microsoft.OpenApi.Models
17
16
/// </summary>
18
17
public class OpenApiSchema : IOpenApiExtensible , IOpenApiReferenceable , IOpenApiSerializable
19
18
{
19
+ private JsonNode _example ;
20
+ private JsonNode _default ;
21
+ private IList < JsonNode > _examples ;
22
+
20
23
/// <summary>
21
24
/// Follow JSON Schema definition. Short text providing information about the data.
22
25
/// </summary>
@@ -149,7 +152,11 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiReferenceable, IOpenApi
149
152
/// Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level.
150
153
/// For example, if type is string, then default can be "foo" but cannot be 1.
151
154
/// </summary>
152
- public virtual JsonNode Default { get ; set ; }
155
+ public virtual JsonNode Default
156
+ {
157
+ get => _default ;
158
+ set => _default = value ;
159
+ }
153
160
154
161
/// <summary>
155
162
/// Relevant only for Schema "properties" definitions. Declares the property as "read only".
@@ -270,14 +277,22 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiReferenceable, IOpenApi
270
277
/// To represent examples that cannot be naturally represented in JSON or YAML,
271
278
/// a string value can be used to contain the example with escaping where necessary.
272
279
/// </summary>
273
- public virtual JsonNode Example { get ; set ; }
280
+ public virtual JsonNode Example
281
+ {
282
+ get => _example ;
283
+ set => _example = value ;
284
+ }
274
285
275
286
/// <summary>
276
287
/// A free-form property to include examples of an instance for this schema.
277
288
/// To represent examples that cannot be naturally represented in JSON or YAML,
278
289
/// a list of values can be used to contain the examples with escaping where necessary.
279
290
/// </summary>
280
- public virtual IList < JsonNode > Examples { get ; set ; }
291
+ public virtual IList < JsonNode > Examples
292
+ {
293
+ get => _examples ;
294
+ set => _examples = value ;
295
+ }
281
296
282
297
/// <summary>
283
298
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
@@ -360,7 +375,7 @@ public OpenApiSchema(OpenApiSchema schema)
360
375
MinLength = schema ? . MinLength ?? MinLength ;
361
376
Pattern = schema ? . Pattern ?? Pattern ;
362
377
MultipleOf = schema ? . MultipleOf ?? MultipleOf ;
363
- Default = schema ? . Default != null ? JsonNodeCloneHelper . Clone ( schema ? . Default ) : null ;
378
+ _default = schema ? . Default != null ? JsonNodeCloneHelper . Clone ( schema ? . Default ) : null ;
364
379
ReadOnly = schema ? . ReadOnly ?? ReadOnly ;
365
380
WriteOnly = schema ? . WriteOnly ?? WriteOnly ;
366
381
AllOf = schema ? . AllOf != null ? new List < OpenApiSchema > ( schema . AllOf ) : null ;
@@ -379,8 +394,8 @@ public OpenApiSchema(OpenApiSchema schema)
379
394
AdditionalPropertiesAllowed = schema ? . AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed ;
380
395
AdditionalProperties = schema ? . AdditionalProperties != null ? new ( schema ? . AdditionalProperties ) : null ;
381
396
Discriminator = schema ? . Discriminator != null ? new ( schema ? . Discriminator ) : null ;
382
- Example = schema ? . Example != null ? JsonNodeCloneHelper . Clone ( schema ? . Example ) : null ;
383
- Examples = schema ? . Examples != null ? new List < JsonNode > ( schema . Examples ) : null ;
397
+ _example = schema ? . Example != null ? JsonNodeCloneHelper . Clone ( schema ? . Example ) : null ;
398
+ _examples = schema ? . Examples != null ? new List < JsonNode > ( schema . Examples ) : null ;
384
399
Enum = schema ? . Enum != null ? new List < JsonNode > ( schema . Enum ) : null ;
385
400
Nullable = schema ? . Nullable ?? Nullable ;
386
401
ExternalDocs = schema ? . ExternalDocs != null ? new ( schema ? . ExternalDocs ) : null ;
@@ -606,7 +621,7 @@ internal void WriteV31Properties(IOpenApiWriter writer)
606
621
writer . WriteProperty ( OpenApiConstants . V31ExclusiveMaximum , V31ExclusiveMaximum ) ;
607
622
writer . WriteProperty ( OpenApiConstants . V31ExclusiveMinimum , V31ExclusiveMinimum ) ;
608
623
writer . WriteProperty ( OpenApiConstants . UnevaluatedProperties , UnevaluatedProperties , false ) ;
609
- writer . WriteOptionalCollection ( OpenApiConstants . Examples , Examples , ( nodeWriter , s ) => nodeWriter . WriteAny ( s ) ) ;
624
+ writer . WriteOptionalCollection ( OpenApiConstants . Examples , _examples , ( nodeWriter , s ) => nodeWriter . WriteAny ( s ) ) ;
610
625
writer . WriteOptionalMap ( OpenApiConstants . PatternProperties , PatternProperties , ( w , s ) => s . SerializeAsV31 ( w ) ) ;
611
626
}
612
627
0 commit comments