Skip to content

Commit 6fed385

Browse files
committed
Add a copy constructor
1 parent cf27ffa commit 6fed385

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,68 @@ internal class OpenApiSchema
263263
/// Reference object.
264264
/// </summary>
265265
public OpenApiReference Reference { get; set; }
266+
267+
/// <summary>
268+
/// Parameterless constructor
269+
/// </summary>
270+
public OpenApiSchema() { }
271+
272+
/// <summary>
273+
/// Initializes a copy of <see cref="OpenApiSchema"/> object
274+
/// </summary>
275+
public OpenApiSchema(OpenApiSchema schema)
276+
{
277+
Title = schema?.Title ?? Title;
278+
Id = schema?.Id ?? Id;
279+
Schema = schema?.Schema ?? Schema;
280+
Comment = schema?.Comment ?? Comment;
281+
Vocabulary = schema?.Vocabulary ?? Vocabulary;
282+
DynamicAnchor = schema?.DynamicAnchor ?? DynamicAnchor;
283+
DynamicRef = schema?.DynamicRef ?? DynamicRef;
284+
RecursiveAnchor = schema?.RecursiveAnchor ?? RecursiveAnchor;
285+
RecursiveRef = schema?.RecursiveRef ?? RecursiveRef;
286+
Definitions = schema?.Definitions != null ? new Dictionary<string, OpenApiSchema>(schema.Definitions) : null;
287+
UnevaluatedProperties = schema?.UnevaluatedProperties ?? UnevaluatedProperties;
288+
V31ExclusiveMaximum = schema?.V31ExclusiveMaximum ?? V31ExclusiveMaximum;
289+
V31ExclusiveMinimum = schema?.V31ExclusiveMinimum ?? V31ExclusiveMinimum;
290+
Type = schema?.Type ?? Type;
291+
Format = schema?.Format ?? Format;
292+
Description = schema?.Description ?? Description;
293+
Maximum = schema?.Maximum ?? Maximum;
294+
ExclusiveMaximum = schema?.ExclusiveMaximum ?? ExclusiveMaximum;
295+
Minimum = schema?.Minimum ?? Minimum;
296+
ExclusiveMinimum = schema?.ExclusiveMinimum ?? ExclusiveMinimum;
297+
MaxLength = schema?.MaxLength ?? MaxLength;
298+
MinLength = schema?.MinLength ?? MinLength;
299+
Pattern = schema?.Pattern ?? Pattern;
300+
MultipleOf = schema?.MultipleOf ?? MultipleOf;
301+
Default = schema?.Default != null ? new(schema?.Default.Node) : null;
302+
ReadOnly = schema?.ReadOnly ?? ReadOnly;
303+
WriteOnly = schema?.WriteOnly ?? WriteOnly;
304+
AllOf = schema?.AllOf != null ? new List<OpenApiSchema>(schema.AllOf) : null;
305+
OneOf = schema?.OneOf != null ? new List<OpenApiSchema>(schema.OneOf) : null;
306+
AnyOf = schema?.AnyOf != null ? new List<OpenApiSchema>(schema.AnyOf) : null;
307+
Not = schema?.Not != null ? new(schema?.Not) : null;
308+
Required = schema?.Required != null ? new HashSet<string>(schema.Required) : null;
309+
Items = schema?.Items != null ? new(schema?.Items) : null;
310+
MaxItems = schema?.MaxItems ?? MaxItems;
311+
MinItems = schema?.MinItems ?? MinItems;
312+
UniqueItems = schema?.UniqueItems ?? UniqueItems;
313+
Properties = schema?.Properties != null ? new Dictionary<string, OpenApiSchema>(schema.Properties) : null;
314+
MaxProperties = schema?.MaxProperties ?? MaxProperties;
315+
MinProperties = schema?.MinProperties ?? MinProperties;
316+
AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed;
317+
AdditionalProperties = schema?.AdditionalProperties != null ? new(schema?.AdditionalProperties) : null;
318+
Discriminator = schema?.Discriminator != null ? new(schema?.Discriminator) : null;
319+
Example = schema?.Example != null ? new(schema?.Example.Node) : null;
320+
Enum = schema?.Enum != null ? new List<OpenApiAny>(schema.Enum) : null;
321+
Nullable = schema?.Nullable ?? Nullable;
322+
ExternalDocs = schema?.ExternalDocs != null ? new(schema?.ExternalDocs) : null;
323+
Deprecated = schema?.Deprecated ?? Deprecated;
324+
Xml = schema?.Xml != null ? new(schema?.Xml) : null;
325+
Extensions = schema?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(schema.Extensions) : null;
326+
UnresolvedReference = schema?.UnresolvedReference ?? UnresolvedReference;
327+
Reference = schema?.Reference != null ? new(schema?.Reference) : null;
328+
}
266329
}
267330
}

0 commit comments

Comments
 (0)