55using System . Collections . Generic ;
66using System . Linq ;
77using System . Text . Json . Nodes ;
8- using Microsoft . OpenApi . Any ;
98using Microsoft . OpenApi . Helpers ;
109using Microsoft . OpenApi . Interfaces ;
1110using Microsoft . OpenApi . Writers ;
@@ -17,6 +16,10 @@ namespace Microsoft.OpenApi.Models
1716 /// </summary>
1817 public class OpenApiSchema : IOpenApiExtensible , IOpenApiReferenceable , IOpenApiSerializable
1918 {
19+ private JsonNode _example ;
20+ private JsonNode _default ;
21+ private IList < JsonNode > _examples ;
22+
2023 /// <summary>
2124 /// Follow JSON Schema definition. Short text providing information about the data.
2225 /// </summary>
@@ -149,7 +152,11 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiReferenceable, IOpenApi
149152 /// Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level.
150153 /// For example, if type is string, then default can be "foo" but cannot be 1.
151154 /// </summary>
152- public virtual JsonNode Default { get ; set ; }
155+ public virtual JsonNode Default
156+ {
157+ get => _default ;
158+ set => _default = value ;
159+ }
153160
154161 /// <summary>
155162 /// Relevant only for Schema "properties" definitions. Declares the property as "read only".
@@ -270,14 +277,22 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiReferenceable, IOpenApi
270277 /// To represent examples that cannot be naturally represented in JSON or YAML,
271278 /// a string value can be used to contain the example with escaping where necessary.
272279 /// </summary>
273- public virtual JsonNode Example { get ; set ; }
280+ public virtual JsonNode Example
281+ {
282+ get => _example ;
283+ set => _example = value ;
284+ }
274285
275286 /// <summary>
276287 /// A free-form property to include examples of an instance for this schema.
277288 /// To represent examples that cannot be naturally represented in JSON or YAML,
278289 /// a list of values can be used to contain the examples with escaping where necessary.
279290 /// </summary>
280- public virtual IList < JsonNode > Examples { get ; set ; }
291+ public virtual IList < JsonNode > Examples
292+ {
293+ get => _examples ;
294+ set => _examples = value ;
295+ }
281296
282297 /// <summary>
283298 /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
@@ -360,7 +375,7 @@ public OpenApiSchema(OpenApiSchema schema)
360375 MinLength = schema ? . MinLength ?? MinLength ;
361376 Pattern = schema ? . Pattern ?? Pattern ;
362377 MultipleOf = schema ? . MultipleOf ?? MultipleOf ;
363- Default = schema ? . Default != null ? JsonNodeCloneHelper . Clone ( schema ? . Default ) : null ;
378+ _default = schema ? . Default != null ? JsonNodeCloneHelper . Clone ( schema ? . Default ) : null ;
364379 ReadOnly = schema ? . ReadOnly ?? ReadOnly ;
365380 WriteOnly = schema ? . WriteOnly ?? WriteOnly ;
366381 AllOf = schema ? . AllOf != null ? new List < OpenApiSchema > ( schema . AllOf ) : null ;
@@ -379,8 +394,8 @@ public OpenApiSchema(OpenApiSchema schema)
379394 AdditionalPropertiesAllowed = schema ? . AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed ;
380395 AdditionalProperties = schema ? . AdditionalProperties != null ? new ( schema ? . AdditionalProperties ) : null ;
381396 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 ;
384399 Enum = schema ? . Enum != null ? new List < JsonNode > ( schema . Enum ) : null ;
385400 Nullable = schema ? . Nullable ?? Nullable ;
386401 ExternalDocs = schema ? . ExternalDocs != null ? new ( schema ? . ExternalDocs ) : null ;
@@ -606,7 +621,7 @@ internal void WriteV31Properties(IOpenApiWriter writer)
606621 writer . WriteProperty ( OpenApiConstants . V31ExclusiveMaximum , V31ExclusiveMaximum ) ;
607622 writer . WriteProperty ( OpenApiConstants . V31ExclusiveMinimum , V31ExclusiveMinimum ) ;
608623 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 ) ) ;
610625 writer . WriteOptionalMap ( OpenApiConstants . PatternProperties , PatternProperties , ( w , s ) => s . SerializeAsV31 ( w ) ) ;
611626 }
612627
0 commit comments