diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index e9701b17c..2dcae12d1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -45,10 +45,10 @@ public OpenApiCallback() { } /// public OpenApiCallback(OpenApiCallback callback) { - PathItems = new(callback.PathItems); - UnresolvedReference = callback.UnresolvedReference; - Reference = new(callback.Reference); - Extensions = new Dictionary(callback.Extensions); + PathItems = callback?.PathItems != null ? new(callback?.PathItems) : null; + UnresolvedReference = callback?.UnresolvedReference ?? UnresolvedReference; + Reference = callback?.Reference != null ? new(callback?.Reference) : null; + Extensions = callback?.Extensions != null ? new Dictionary(callback.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index c23e569c5..1f41080bc 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -78,16 +78,16 @@ public OpenApiComponents() { } /// public OpenApiComponents(OpenApiComponents components) { - Schemas = new Dictionary(components.Schemas); - Responses = new Dictionary(components.Responses); - Parameters = new Dictionary(components.Parameters); - Examples = new Dictionary(components.Examples); - RequestBodies = new Dictionary(components.RequestBodies); - Headers = new Dictionary(components.Headers); - SecuritySchemes = new Dictionary(components.SecuritySchemes); - Links = new Dictionary(components.Links); - Callbacks = new Dictionary(components.Callbacks); - Extensions = new Dictionary(components.Extensions); + Schemas = components?.Schemas != null ? new Dictionary(components.Schemas) : null; + Responses = components?.Responses != null ? new Dictionary(components.Responses) : null; + Parameters = components?.Parameters != null ? new Dictionary(components.Parameters) : null; + Examples = components?.Examples != null ? new Dictionary(components.Examples) : null; + RequestBodies = components?.RequestBodies != null ? new Dictionary(components.RequestBodies) : null; + Headers = components?.Headers != null ? new Dictionary(components.Headers) : null; + SecuritySchemes = components?.SecuritySchemes != null ? new Dictionary(components.SecuritySchemes) : null; + Links = components?.Links != null ? new Dictionary(components.Links) : null; + Callbacks = components?.Callbacks != null ? new Dictionary(components.Callbacks) : null; + Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 9447d424e..352697bf2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -45,10 +45,10 @@ public OpenApiContact() { } /// public OpenApiContact(OpenApiContact contact) { - Name = contact.Name; - Url = new Uri(contact.Url.OriginalString); - Email = contact.Email; - Extensions = new Dictionary(contact.Extensions); + Name = contact?.Name ?? Name; + Url = contact?.Url != null ? new Uri(contact.Url.OriginalString) : null; + Email = contact?.Email ?? Email; + Extensions = contact?.Extensions != null ? new Dictionary(contact.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index e03c7d59a..9ae7f0e6a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -32,8 +32,8 @@ public OpenApiDiscriminator() { } /// public OpenApiDiscriminator(OpenApiDiscriminator discriminator) { - PropertyName = discriminator.PropertyName; - Mapping = new Dictionary(discriminator.Mapping); + PropertyName = discriminator?.PropertyName ?? PropertyName; + Mapping = discriminator?.Mapping != null ? new Dictionary(discriminator.Mapping) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 44cbc71ab..01edcebba 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -72,15 +72,15 @@ public OpenApiDocument() {} /// public OpenApiDocument(OpenApiDocument document) { - Workspace = new(document.Workspace); - Info = new(document.Info); - Servers = new List(document.Servers); - Paths = new(document.Paths); - Components = new(document.Components); - SecurityRequirements = new List(document.SecurityRequirements); - Tags = new List(document.Tags); - ExternalDocs = new(document.ExternalDocs); - Extensions = new Dictionary(document.Extensions); + Workspace = document?.Workspace != null ? new(document?.Workspace) : null; + Info = document?.Info != null ? new(document?.Info) : null; + Servers = document?.Servers != null ? new List(document.Servers) : null; + Paths = document?.Paths != null ? new(document?.Paths) : null; + Components = document?.Components != null ? new(document?.Components) : null; + SecurityRequirements = document?.SecurityRequirements != null ? new List(document.SecurityRequirements) : null; + Tags = document?.Tags != null ? new List(document.Tags) : null; + ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null; + Extensions = document?.Extensions != null ? new Dictionary(document.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 533cb7e80..ddb4162bc 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -63,12 +63,12 @@ public OpenApiEncoding() {} /// public OpenApiEncoding(OpenApiEncoding encoding) { - ContentType = encoding.ContentType; - Headers = new Dictionary(encoding.Headers); - Style = encoding.Style; - Explode = encoding.Explode; - AllowReserved = encoding.AllowReserved; - Extensions = new Dictionary(encoding.Extensions); + ContentType = encoding?.ContentType ?? ContentType; + Headers = encoding?.Headers != null ? new Dictionary(encoding.Headers) : null; + Style = encoding?.Style ?? Style; + Explode = encoding?.Explode ?? Explode; + AllowReserved = encoding?.AllowReserved ?? AllowReserved; + Extensions = encoding?.Extensions != null ? new Dictionary(encoding.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 5e105be26..4d091a361 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -64,13 +64,13 @@ public OpenApiExample() {} /// public OpenApiExample(OpenApiExample example) { - Summary = example.Summary; - Description = example.Description; - Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example.Value); - ExternalValue = example.ExternalValue; - Extensions = new Dictionary(example.Extensions); - Reference = new(example.Reference); - UnresolvedReference = example.UnresolvedReference; + Summary = example?.Summary ?? Summary; + Description = example?.Description ?? Description; + Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); + ExternalValue = example?.ExternalValue ?? ExternalValue; + Extensions = example?.Extensions != null ? new Dictionary(example.Extensions) : null; + Reference = example?.Reference != null ? new(example?.Reference) : null; + UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 95af8f01b..9ad3b9e55 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -39,9 +39,9 @@ public OpenApiExternalDocs() {} /// public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { - Description = externalDocs.Description; - Url = new Uri(externalDocs.Url.OriginalString); - Extensions = new Dictionary(externalDocs.Extensions); + Description = externalDocs?.Description ?? Description; + Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString) : null; + Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index b91440df8..fb4411478 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -96,20 +96,20 @@ public OpenApiHeader() {} /// public OpenApiHeader(OpenApiHeader header) { - UnresolvedReference = header.UnresolvedReference; - Reference = new(header.Reference); - Description = header.Description; - Required = header.Required; - Deprecated = header.Deprecated; - AllowEmptyValue = header.AllowEmptyValue; - Style = header.Style; - Explode = header.Explode; - AllowReserved = header.AllowReserved; - Schema = new(header.Schema); - Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header.Example); - Examples = new Dictionary(header.Examples); - Content = new Dictionary(header.Content); - Extensions = new Dictionary(header.Extensions); + UnresolvedReference = header?.UnresolvedReference ?? UnresolvedReference; + Reference = header?.Reference != null ? new(header?.Reference) : null; + Description = header?.Description ?? Description; + Required = header?.Required ?? Required; + Deprecated = header?.Deprecated ?? Deprecated; + AllowEmptyValue = header?.AllowEmptyValue ?? AllowEmptyValue; + Style = header?.Style ?? Style; + Explode = header?.Explode ?? Explode; + AllowReserved = header?.AllowReserved ?? AllowReserved; + Schema = header?.Schema != null ? new(header?.Schema) : null; + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example); + Examples = header?.Examples != null ? new Dictionary(header.Examples) : null; + Content = header?.Content != null ? new Dictionary(header.Content) : null; + Extensions = header?.Extensions != null ? new Dictionary(header.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index c5a44c448..df0aa0a49 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -59,13 +59,13 @@ public OpenApiInfo() {} /// public OpenApiInfo(OpenApiInfo info) { - Title = info.Title; - Description = info.Description; - Version = info.Version; - TermsOfService = info.TermsOfService; - Contact = new(info.Contact); - License = new(info.License); - Extensions = new Dictionary(info.Extensions); + Title = info?.Title ?? Title; + Description = info?.Description ?? Description; + Version = info?.Version ?? Version; + TermsOfService = info?.TermsOfService ?? TermsOfService; + Contact = info?.Contact != null ? new(info?.Contact) : null; + License = info?.License != null ? new(info?.License) : null; + Extensions = info?.Extensions != null ? new Dictionary(info.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 431789aac..1a8d1a4d8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -39,9 +39,9 @@ public OpenApiLicense() {} /// public OpenApiLicense(OpenApiLicense license) { - Name = license.Name; - Url = new Uri(license.Url.OriginalString); - Extensions = new Dictionary(license.Extensions); + Name = license?.Name ?? Name; + Url = license?.Url != null ? new Uri(license.Url.OriginalString) : null; + Extensions = license?.Extensions != null ? new Dictionary(license.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 6ba3a65fd..b682744e9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -71,15 +71,15 @@ public OpenApiLink() {} /// public OpenApiLink(OpenApiLink link) { - OperationRef = link.OperationRef; - OperationId = link.OperationId; - Parameters = new(link.Parameters); - RequestBody = new(link.RequestBody); - Description = link.Description; - Server = new(link.Server); - Extensions = new Dictionary(link.Extensions); - UnresolvedReference = link.UnresolvedReference; - Reference = new(link.Reference); + OperationRef = link?.OperationRef ?? OperationRef; + OperationId = link?.OperationId ?? OperationId; + Parameters = link?.Parameters != null ? new(link?.Parameters) : null; + RequestBody = link?.RequestBody != null ? new(link?.RequestBody) : null; + Description = link?.Description ?? Description; + Server = link?.Server != null ? new(link?.Server) : null; + Extensions = link?.Extensions != null ? new Dictionary(link.Extensions) : null; + UnresolvedReference = link?.UnresolvedReference ?? UnresolvedReference; + Reference = link?.Reference != null ? new(link?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 94dcbdfa7..63a58cd02 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -53,11 +53,11 @@ public OpenApiMediaType() {} /// public OpenApiMediaType(OpenApiMediaType mediaType) { - Schema = new(mediaType.Schema); - Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType.Example); - Examples = new Dictionary(mediaType.Examples); - Encoding = new Dictionary(mediaType.Encoding); - Extensions = new Dictionary(mediaType.Extensions); + Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null; + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); + Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples) : null; + Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding) : null; + Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 02856d4cd..c6f91fbd8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -51,11 +51,11 @@ public OpenApiOAuthFlow() {} /// public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) { - AuthorizationUrl = new Uri(oAuthFlow.AuthorizationUrl.OriginalString); - TokenUrl = new Uri(oAuthFlow.TokenUrl.OriginalString); - RefreshUrl = new Uri(oAuthFlow.RefreshUrl.OriginalString); - Scopes = new Dictionary(oAuthFlow.Scopes); - Extensions = new Dictionary(oAuthFlow.Extensions); + AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString) : null; + TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString) : null; + RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString) : null; + Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow.Scopes) : null; + Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index 973a403e0..8443e6730 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -49,11 +49,11 @@ public OpenApiOAuthFlows() {} /// public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) { - Implicit = new(oAuthFlows.Implicit); - Password = new(oAuthFlows.Password); - ClientCredentials = new(oAuthFlows.ClientCredentials); - AuthorizationCode = new(oAuthFlows.AuthorizationCode); - Extensions = new Dictionary(oAuthFlows.Extensions); + Implicit = oAuthFlows?.Implicit != null ? new(oAuthFlows?.Implicit) : null; + Password = oAuthFlows?.Password != null ? new(oAuthFlows?.Password) : null; + ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows?.ClientCredentials) : null; + AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows?.AuthorizationCode) : null; + Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 775532684..ba0af7317 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -116,19 +116,19 @@ public OpenApiOperation() {} /// public OpenApiOperation(OpenApiOperation operation) { - Tags = new List(operation.Tags); - Summary = operation.Summary; - Description = operation.Description; - ExternalDocs = new(operation.ExternalDocs); - OperationId = operation.OperationId; - Parameters = new List(operation.Parameters); - RequestBody = new(operation.RequestBody); - Responses = new(operation.Responses); - Callbacks = new Dictionary(operation.Callbacks); - Deprecated = operation.Deprecated; - Security = new List(operation.Security); - Servers = new List(operation.Servers); - Extensions = new Dictionary(operation.Extensions); + Tags = new List(operation?.Tags); + Summary = operation?.Summary ?? Summary; + Description = operation?.Description ?? Description; + ExternalDocs = operation?.ExternalDocs != null ? new(operation?.ExternalDocs) : null; + OperationId = operation?.OperationId ?? OperationId; + Parameters = operation?.Parameters != null ? new List(operation.Parameters) : null; + RequestBody = new(operation?.RequestBody); + Responses = operation?.Responses != null ? new(operation?.Responses) : null; + Callbacks = operation?.Callbacks != null ? new Dictionary(operation.Callbacks) : null; + Deprecated = operation?.Deprecated ?? Deprecated; + Security = operation?.Security != null ? new List(operation.Security) : null; + Servers = operation?.Servers != null ? new List(operation.Servers) : null; + Extensions = operation?.Extensions != null ? new Dictionary(operation.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index f0b21b0d9..c6f06b1f6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -146,22 +146,22 @@ public OpenApiParameter() {} /// public OpenApiParameter(OpenApiParameter parameter) { - UnresolvedReference = parameter.UnresolvedReference; - Reference = new(parameter.Reference); - Name = parameter.Name; - In = parameter.In; - Description = parameter.Description; - Required = parameter.Required; - Style = parameter.Style; - Explode = parameter.Explode; - AllowReserved = parameter.AllowReserved; - Schema = new(parameter.Schema); - Examples = new Dictionary(parameter.Examples); - Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter.Example); - Content = new Dictionary(parameter.Content); - Extensions = new Dictionary(parameter.Extensions); - AllowEmptyValue = parameter.AllowEmptyValue; - Deprecated = parameter.Deprecated; + UnresolvedReference = parameter?.UnresolvedReference ?? UnresolvedReference; + Reference = parameter?.Reference != null ? new(parameter?.Reference) : null; + Name = parameter?.Name ?? Name; + In = parameter?.In ?? In; + Description = parameter?.Description ?? Description; + Required = parameter?.Required ?? Required; + Style = parameter?.Style ?? Style; + Explode = parameter?.Explode ?? Explode; + AllowReserved = parameter?.AllowReserved ?? AllowReserved; + Schema = parameter?.Schema != null ? new(parameter?.Schema) : null; + Examples = parameter?.Examples != null ? new Dictionary(parameter.Examples) : null; + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); + Content = parameter?.Content != null ? new Dictionary(parameter.Content) : null; + Extensions = parameter?.Extensions != null ? new Dictionary(parameter.Extensions) : null; + AllowEmptyValue = parameter?.AllowEmptyValue ?? AllowEmptyValue; + Deprecated = parameter?.Deprecated ?? Deprecated; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 8ce83c9eb..ddd358dc2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -75,14 +75,14 @@ public OpenApiPathItem() {} /// public OpenApiPathItem(OpenApiPathItem pathItem) { - Summary = pathItem.Summary; - Description = pathItem.Description; - Operations = new Dictionary(pathItem.Operations); - Servers = new List(pathItem.Servers); - Parameters = new List(pathItem.Parameters); - Extensions = new Dictionary(pathItem.Extensions); - UnresolvedReference = pathItem.UnresolvedReference; - Reference = new(pathItem.Reference); + Summary = pathItem?.Summary ?? Summary; + Description = pathItem?.Description ?? Description; + Operations = pathItem?.Operations != null ? new Dictionary(pathItem.Operations) : null; + Servers = pathItem?.Servers != null ? new List(pathItem.Servers) : null; + Parameters = pathItem?.Parameters != null ? new List(pathItem.Parameters) : null; + Extensions = pathItem?.Extensions != null ? new Dictionary(pathItem.Extensions) : null; + UnresolvedReference = pathItem?.UnresolvedReference ?? UnresolvedReference; + Reference = pathItem?.Reference != null ? new(pathItem?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index 9213e77bc..31cc5a6e8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -122,10 +122,10 @@ public OpenApiReference() {} /// public OpenApiReference(OpenApiReference reference) { - ExternalResource = reference.ExternalResource; - Type = reference.Type; - Id = reference.Id; - HostDocument = new(reference.HostDocument); + ExternalResource = reference?.ExternalResource; + Type = reference?.Type; + Id = reference?.Id; + HostDocument = new(reference?.HostDocument); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index b82b67e8a..9016fd7a3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -55,12 +55,12 @@ public OpenApiRequestBody() { } /// public OpenApiRequestBody(OpenApiRequestBody requestBody) { - UnresolvedReference = requestBody.UnresolvedReference; - Reference = new(requestBody.Reference); - Description = requestBody.Description; - Required = requestBody.Required; - Content = new Dictionary(requestBody.Content); - Extensions = new Dictionary(requestBody.Extensions); + UnresolvedReference = requestBody?.UnresolvedReference ?? UnresolvedReference; + Reference = requestBody?.Reference != null ? new(requestBody?.Reference) : null; + Description = requestBody?.Description ?? Description; + Required = requestBody?.Required ?? Required; + Content = requestBody?.Content != null ? new Dictionary(requestBody.Content) : null; + Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index cf0c796e6..a173f6c1a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -61,13 +61,13 @@ public OpenApiResponse() {} /// public OpenApiResponse(OpenApiResponse response) { - Description = response.Description; - Headers = new Dictionary(response.Headers); - Content = new Dictionary(response.Content); - Links = new Dictionary(response.Links); - Extensions = new Dictionary(response.Extensions); - UnresolvedReference = response.UnresolvedReference; - Reference = new(response.Reference); + Description = response?.Description ?? Description; + Headers = response?.Headers != null ? new Dictionary(response.Headers) : null; + Content = response?.Content != null ? new Dictionary(response.Content) : null; + Links = response?.Links != null ? new Dictionary(response.Links) : null; + Extensions = response?.Extensions != null ? new Dictionary(response.Extensions) : null; + UnresolvedReference = response?.UnresolvedReference ?? UnresolvedReference; + Reference = response?.Reference != null ? new(response?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index d43756887..3886a5555 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -252,44 +252,44 @@ public OpenApiSchema() {} /// public OpenApiSchema(OpenApiSchema schema) { - Title = schema.Title; - Type = schema.Type; - Format = schema.Format; - Description = schema.Description; - Maximum = schema.Maximum; - ExclusiveMaximum = schema.ExclusiveMaximum; - Minimum = schema.Minimum; - ExclusiveMinimum = schema.ExclusiveMinimum; - MaxLength = schema.MaxLength; - MinLength = schema.MinLength; - Pattern = schema.Pattern; - MultipleOf = schema.MultipleOf; - Default = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema.Default); - ReadOnly = schema.ReadOnly; - WriteOnly = schema.WriteOnly; - AllOf = new List(schema.AllOf); - OneOf = new List(schema.OneOf); - AnyOf = new List(schema.AnyOf); - Not = new(schema.Not); - Required = new HashSet(schema.Required); - Items = new(schema.Items); - MaxItems = schema.MaxItems; - MinItems = schema.MinItems; - UniqueItems = schema.UniqueItems; - Properties = new Dictionary(schema.Properties); - MaxProperties = schema.MaxProperties; - MinProperties = schema.MinProperties; - AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; - AdditionalProperties = new(schema.AdditionalProperties); - Discriminator = new(schema.Discriminator); - Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema.Example); - Enum = new List(schema.Enum); - Nullable = schema.Nullable; - ExternalDocs = new(schema.ExternalDocs); - Deprecated = schema.Deprecated; - Xml = new(schema.Xml); - UnresolvedReference = schema.UnresolvedReference; - Reference = new(schema.Reference); + Title = schema?.Title ?? Title; + Type = schema?.Type ?? Type; + Format = schema?.Format ?? Format; + Description = schema?.Description ?? Description; + Maximum = schema?.Maximum ?? Maximum; + ExclusiveMaximum = schema?.ExclusiveMaximum ?? ExclusiveMaximum; + Minimum = schema?.Minimum ?? Minimum; + ExclusiveMinimum = schema?.ExclusiveMinimum ?? ExclusiveMinimum; + MaxLength = schema?.MaxLength ?? MaxLength; + MinLength = schema?.MinLength ?? MinLength; + Pattern = schema?.Pattern ?? Pattern; + MultipleOf = schema?.MultipleOf ?? MultipleOf; + Default = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema?.Default); + ReadOnly = schema?.ReadOnly ?? ReadOnly; + WriteOnly = schema?.WriteOnly ?? WriteOnly; + AllOf = schema?.AllOf != null ? new List(schema.AllOf) : null; + OneOf = schema?.OneOf != null ? new List(schema.OneOf) : null; + AnyOf = schema?.AnyOf != null ? new List(schema.AnyOf) : null; + Not = schema?.Not != null ? new(schema?.Not) : null; + Required = schema?.Required != null ? new HashSet(schema.Required) : null; + Items = schema?.Items != null ? new(schema?.Items) : null; + MaxItems = schema?.MaxItems ?? MaxItems; + MinItems = schema?.MinItems ?? MinItems; + UniqueItems = schema?.UniqueItems ?? UniqueItems; + Properties = schema?.Properties != null ? new Dictionary(schema.Properties) : null; + MaxProperties = schema?.MaxProperties ?? MaxProperties; + MinProperties = schema?.MinProperties ?? MinProperties; + AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed; + AdditionalProperties = new(schema?.AdditionalProperties); + Discriminator = schema?.Discriminator != null ? new(schema?.Discriminator) : null; + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema?.Example); + Enum = schema?.Enum != null ? new List(schema.Enum) : null; + Nullable = schema?.Nullable ?? Nullable; + ExternalDocs = schema?.ExternalDocs != null ? new(schema?.ExternalDocs) : null; + Deprecated = schema?.Deprecated ?? Deprecated; + Xml = schema?.Xml != null ? new(schema?.Xml) : null; + UnresolvedReference = schema?.UnresolvedReference ?? UnresolvedReference; + Reference = schema?.Reference != null ? new(schema?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index b87adf573..913e70441 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -84,17 +84,17 @@ public OpenApiSecurityScheme() {} /// public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) { - Type = securityScheme.Type; - Description = securityScheme.Description; - Name = securityScheme.Name; - In = securityScheme.In; - Scheme = securityScheme.Scheme; - BearerFormat = securityScheme.BearerFormat; - Flows = new(securityScheme.Flows); - OpenIdConnectUrl = new Uri(securityScheme.OpenIdConnectUrl.OriginalString); - Extensions = new Dictionary(securityScheme.Extensions); - UnresolvedReference = securityScheme.UnresolvedReference; - Reference = new(securityScheme.Reference); + Type = securityScheme?.Type ?? Type; + Description = securityScheme?.Description ?? Description; + Name = securityScheme?.Name ?? Name; + In = securityScheme?.In ?? In; + Scheme = securityScheme?.Scheme ?? Scheme; + BearerFormat = securityScheme?.BearerFormat ?? BearerFormat; + Flows = securityScheme?.Flows != null ? new(securityScheme?.Flows) : null; + OpenIdConnectUrl = securityScheme?.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString) : null; + Extensions = securityScheme?.Extensions != null ? new Dictionary(securityScheme.Extensions) : null; + UnresolvedReference = securityScheme?.UnresolvedReference ?? UnresolvedReference; + Reference = securityScheme?.Reference != null ? new(securityScheme?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 875bef5c7..b3b1d1287 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -46,10 +46,10 @@ public OpenApiServer() {} /// public OpenApiServer(OpenApiServer server) { - Description = server.Description; - Url = server.Url; - Variables = new Dictionary(server.Variables); - Extensions = new Dictionary(server.Extensions); + Description = server?.Description ?? Description; + Url = server?.Url ?? Url; + Variables = server?.Variables != null ? new Dictionary(server.Variables) : null; + Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index b1f222e83..70164bc59 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -44,10 +44,10 @@ public OpenApiServerVariable() {} /// public OpenApiServerVariable(OpenApiServerVariable serverVariable) { - Description = serverVariable.Description; - Default = serverVariable.Default; - Enum = new List(serverVariable.Enum); - Extensions = new Dictionary(serverVariable.Extensions); + Description = serverVariable?.Description; + Default = serverVariable?.Default; + Enum = serverVariable?.Enum != null ? new List(serverVariable?.Enum) : serverVariable?.Enum; + Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable?.Extensions) : serverVariable?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 5ecfa0363..ba4129142 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -53,12 +53,12 @@ public OpenApiTag() {} /// public OpenApiTag(OpenApiTag tag) { - Name = tag.Name; - Description = tag.Description; - ExternalDocs = new(tag.ExternalDocs); - Extensions = new Dictionary(tag.Extensions); - UnresolvedReference = tag.UnresolvedReference; - Reference = new(tag.Reference); + Name = tag?.Name ?? Name; + Description = tag?.Description ?? Description; + ExternalDocs = tag?.ExternalDocs != null ? new(tag?.ExternalDocs) : null; + Extensions = tag?.Extensions != null ? new Dictionary(tag.Extensions) : null; + UnresolvedReference = tag?.UnresolvedReference ?? UnresolvedReference; + Reference = tag?.Reference != null ? new(tag?.Reference) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index eb48132ad..c6719d85e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -56,12 +56,12 @@ public OpenApiXml() {} /// public OpenApiXml(OpenApiXml xml) { - Name = xml.Name; - Namespace = xml.Namespace; - Prefix = xml.Prefix; - Attribute = xml.Attribute; - Wrapped = xml.Wrapped; - Extensions = new Dictionary(xml.Extensions); + Name = xml?.Name ?? Name; + Namespace = xml?.Namespace ?? Namespace; + Prefix = xml?.Prefix ?? Prefix; + Attribute = xml?.Attribute ?? Attribute; + Wrapped = xml?.Wrapped ?? Wrapped; + Extensions = xml?.Extensions != null ? new Dictionary(xml.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index 85c64dd30..1a1f12a18 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -26,8 +26,8 @@ public RuntimeExpressionAnyWrapper() {} /// public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { - Any = OpenApiAnyCloneHelper.CloneFromCopyConstructor(runtimeExpressionAnyWrapper.Any); - Expression = runtimeExpressionAnyWrapper.Expression; + Any = OpenApiAnyCloneHelper.CloneFromCopyConstructor(runtimeExpressionAnyWrapper?.Any); + Expression = runtimeExpressionAnyWrapper?.Expression; } ///