From b0557a13ef24cc7f5f3d9e3a02432f9e84688158 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 12 Aug 2022 15:43:20 +0300 Subject: [PATCH 1/4] Add defensive programming --- .../Models/OpenApiCallback.cs | 8 +- .../Models/OpenApiComponents.cs | 20 ++--- .../Models/OpenApiContact.cs | 8 +- .../Models/OpenApiDiscriminator.cs | 4 +- .../Models/OpenApiDocument.cs | 18 ++--- .../Models/OpenApiEncoding.cs | 12 +-- .../Models/OpenApiExample.cs | 14 ++-- .../Models/OpenApiExternalDocs.cs | 6 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 28 +++---- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 14 ++-- .../Models/OpenApiLicense.cs | 6 +- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 18 ++--- .../Models/OpenApiMediaType.cs | 10 +-- .../Models/OpenApiOAuthFlow.cs | 10 +-- .../Models/OpenApiOAuthFlows.cs | 10 +-- .../Models/OpenApiOperation.cs | 26 +++---- .../Models/OpenApiParameter.cs | 32 ++++---- .../Models/OpenApiPathItem.cs | 16 ++-- .../Models/OpenApiReference.cs | 8 +- .../Models/OpenApiRequestBody.cs | 12 +-- .../Models/OpenApiResponse.cs | 14 ++-- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 76 +++++++++---------- .../Models/OpenApiSecurityScheme.cs | 22 +++--- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 8 +- .../Models/OpenApiServerVariable.cs | 8 +- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 12 +-- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 12 +-- .../Models/RuntimeExpressionAnyWrapper.cs | 4 +- 28 files changed, 218 insertions(+), 218 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index e9701b17c..beed0ad06 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 = new(callback?.PathItems); + UnresolvedReference = callback?.UnresolvedReference ?? false; + Reference = new(callback?.Reference); + Extensions = callback?.Extensions != null ? new Dictionary(callback?.Extensions) : callback?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index c23e569c5..7e4a481ac 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) : components?.Schemas; + Responses = components?.Responses != null ? new Dictionary(components?.Responses) : components?.Responses; + Parameters = components?.Parameters != null ? new Dictionary(components?.Parameters) : components?.Parameters; + Examples = components?.Examples != null ? new Dictionary(components?.Examples) : components?.Examples; + RequestBodies = components?.RequestBodies != null ? new Dictionary(components?.RequestBodies) : components?.RequestBodies; + Headers = components?.Headers != null ? new Dictionary(components?.Headers) : components?.Headers; + SecuritySchemes = components?.SecuritySchemes != null ? new Dictionary(components?.SecuritySchemes) : components?.SecuritySchemes; + Links = components?.Links != null ? new Dictionary(components?.Links) : components?.Links; + Callbacks = components?.Callbacks != null ? new Dictionary(components?.Callbacks) : components?.Callbacks; + Extensions = components?.Extensions != null ? new Dictionary(components?.Extensions) : components?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 9447d424e..28001e928 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; + Url = contact?.Url; + Email = contact?.Email; + Extensions = contact?.Extensions != null ? new Dictionary(contact?.Extensions) : contact?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index e03c7d59a..f39819a0a 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; + Mapping = discriminator?.Mapping != null ? new Dictionary(discriminator?.Mapping) : discriminator?.Mapping; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 44cbc71ab..21c5f2e53 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 = new(document?.Workspace); + Info = new(document?.Info); + Servers = document?.Servers != null ? new List(document?.Servers) : document?.Servers; + Paths = new(document?.Paths); + Components = new(document?.Components); + SecurityRequirements = document?.SecurityRequirements != null ? new List(document?.SecurityRequirements) : document?.SecurityRequirements; + Tags = document?.Tags != null ? new List(document?.Tags) : document?.Tags; + ExternalDocs = new(document?.ExternalDocs); + Extensions = document?.Extensions != null ? new Dictionary(document?.Extensions) : document?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 533cb7e80..bc154e8fb 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; + Headers = encoding?.Headers != null ? new Dictionary(encoding?.Headers) : encoding?.Headers; + Style = encoding?.Style; + Explode = encoding?.Explode ?? false; + AllowReserved = encoding?.AllowReserved ?? false; + Extensions = encoding?.Extensions != null ? new Dictionary(encoding?.Extensions) : encoding?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 5e105be26..b9bfc031a 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; + Description = example?.Description; + Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); + ExternalValue = example?.ExternalValue; + Extensions = example?.Extensions != null ? new Dictionary(example?.Extensions) : example?.Extensions; + Reference = new(example?.Reference); + UnresolvedReference = example?.UnresolvedReference ?? false; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 95af8f01b..040b7d674 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; + Url = externalDocs?.Url != null ? new Uri(externalDocs?.Url?.OriginalString) : externalDocs?.Url; + Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs?.Extensions) : externalDocs?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index b91440df8..a7ca745d2 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 ?? false; + Reference = new(header?.Reference); + Description = header?.Description; + Required = header?.Required ?? false; + Deprecated = header?.Deprecated ?? false; + AllowEmptyValue = header?.AllowEmptyValue ?? false; + Style = header?.Style; + Explode = header?.Explode ?? false; + AllowReserved = header?.AllowReserved ?? false; + Schema = new(header?.Schema); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example); + Examples = header?.Examples != null ? new Dictionary(header?.Examples) : header?.Examples; + Content = header?.Content != null ? new Dictionary(header?.Content) : header?.Content; + Extensions = header?.Extensions != null ? new Dictionary(header?.Extensions) : header?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index c5a44c448..1dcae81e2 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; + Description = info?.Description; + Version = info?.Version; + TermsOfService = info?.TermsOfService; + Contact = new(info?.Contact); + License = new(info?.License); + Extensions = info?.Extensions != null ? new Dictionary(info?.Extensions) : info?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 431789aac..399441b46 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; + Url = license?.Url != null ? new Uri(license?.Url?.OriginalString) : license?.Url; + Extensions = license?.Extensions != null ? new Dictionary(license?.Extensions) : license?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 6ba3a65fd..3a5a72c1d 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; + OperationId = link?.OperationId; + Parameters = new(link?.Parameters); + RequestBody = new(link?.RequestBody); + Description = link?.Description; + Server = new(link?.Server); + Extensions = link?.Extensions != null ? new Dictionary(link?.Extensions) : link?.Extensions; + UnresolvedReference = link?.UnresolvedReference ?? false; + Reference = new(link?.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 94dcbdfa7..b6245f202 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 = new(mediaType?.Schema); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); + Examples = mediaType?.Examples != null ? new Dictionary(mediaType?.Examples) : mediaType?.Examples; + Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType?.Encoding) : mediaType?.Encoding; + Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType?.Extensions) : mediaType?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 02856d4cd..f5a9b46c4 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) : oAuthFlow?.AuthorizationUrl; + TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow?.TokenUrl?.OriginalString) : oAuthFlow?.TokenUrl; + RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow?.RefreshUrl?.OriginalString) : oAuthFlow?.RefreshUrl; + Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow?.Scopes) : oAuthFlow?.Scopes; + Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow?.Extensions) : oAuthFlow?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index 973a403e0..d286c7641 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 = new(oAuthFlows?.Implicit); + Password = new(oAuthFlows?.Password); + ClientCredentials = new(oAuthFlows?.ClientCredentials); + AuthorizationCode = new(oAuthFlows?.AuthorizationCode); + Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows?.Extensions) : oAuthFlows?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 775532684..e7f8b8910 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; + Description = operation?.Description; + ExternalDocs = new(operation?.ExternalDocs); + OperationId = operation?.OperationId; + Parameters = operation?.Parameters != null ? new List(operation?.Parameters) : operation?.Parameters; + RequestBody = new(operation?.RequestBody); + Responses = new(operation?.Responses); + Callbacks = operation?.Callbacks != null ? new Dictionary(operation?.Callbacks) : operation?.Callbacks; + Deprecated = operation?.Deprecated ?? false; + Security = operation?.Security != null ? new List(operation?.Security) : operation?.Security; + Servers = operation?.Servers != null ? new List(operation?.Servers) : operation?.Servers; + Extensions = operation?.Extensions != null ? new Dictionary(operation?.Extensions) : operation?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index f0b21b0d9..7a429ef0a 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 ?? false; + Reference = new(parameter?.Reference); + Name = parameter?.Name; + In = parameter?.In; + Description = parameter?.Description; + Required = parameter?.Required ?? false; + Style = parameter?.Style; + Explode = parameter?.Explode ?? false; + AllowReserved = parameter?.AllowReserved ?? false; + Schema = new(parameter?.Schema); + Examples = parameter?.Examples != null ? new Dictionary(parameter?.Examples) : parameter?.Examples; + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); + Content = parameter?.Content != null ? new Dictionary(parameter?.Content) : parameter?.Content; + Extensions = parameter?.Extensions != null ? new Dictionary(parameter?.Extensions) : parameter?.Extensions; + AllowEmptyValue = parameter?.AllowEmptyValue ?? false; + Deprecated = parameter?.Deprecated ?? false; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 8ce83c9eb..89313be87 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; + Description = pathItem?.Description; + Operations = pathItem?.Operations != null ? new Dictionary(pathItem?.Operations) : pathItem?.Operations; + Servers = pathItem?.Servers != null ? new List(pathItem?.Servers) : pathItem?.Servers; + Parameters = pathItem?.Parameters != null ? new List(pathItem?.Parameters) : pathItem?.Parameters; + Extensions = pathItem?.Extensions != null ? new Dictionary(pathItem?.Extensions) : pathItem?.Extensions; + UnresolvedReference = pathItem?.UnresolvedReference ?? false; + Reference = new(pathItem?.Reference); } /// 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..6e7bdaf77 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 ?? false; + Reference = new(requestBody?.Reference); + Description = requestBody?.Description; + Required = requestBody?.Required ?? false; + Content = requestBody?.Content != null ? new Dictionary(requestBody?.Content) : requestBody?.Content; + Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody?.Extensions) : requestBody?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index cf0c796e6..46b7b63b0 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; + Headers = response?.Headers != null ? new Dictionary(response?.Headers) : response?.Headers; + Content = response?.Content != null ? new Dictionary(response?.Content) : response?.Content; + Links = response?.Links != null ? new Dictionary(response?.Links) : response?.Links; + Extensions = response?.Extensions != null ? new Dictionary(response?.Extensions) : response?.Extensions; + UnresolvedReference = response?.UnresolvedReference ?? false; + Reference = new(response?.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index d43756887..45d520b3a 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; + 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 ?? false; + WriteOnly = schema?.WriteOnly ?? false; + AllOf = schema?.AllOf != null ? new List(schema?.AllOf) : schema?.AllOf; + OneOf = schema?.OneOf != null ? new List(schema?.OneOf) : schema?.OneOf; + AnyOf = schema?.AnyOf != null ? new List(schema?.AnyOf) : schema?.AnyOf; + Not = new(schema?.Not); + Required = schema?.Required != null ? new HashSet(schema?.Required) : schema?.Required; + Items = new(schema?.Items); + MaxItems = schema?.MaxItems; + MinItems = schema?.MinItems; + UniqueItems = schema?.UniqueItems; + Properties = schema?.Properties != null ? new Dictionary(schema?.Properties) : schema?.Properties; + MaxProperties = schema?.MaxProperties; + MinProperties = schema?.MinProperties; + AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? false; + AdditionalProperties = new(schema?.AdditionalProperties); + Discriminator = new(schema?.Discriminator); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema?.Example); + Enum = schema?.Enum != null ? new List(schema?.Enum) : schema?.Enum; + Nullable = schema?.Nullable ?? false; + ExternalDocs = new(schema?.ExternalDocs); + Deprecated = schema?.Deprecated ?? false; + Xml = new(schema?.Xml); + UnresolvedReference = schema?.UnresolvedReference; + Reference = new(schema?.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index b87adf573..1bc427e9a 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 = (SecuritySchemeType)(securityScheme?.Type); + Description = securityScheme?.Description; + Name = securityScheme?.Name; + In = (ParameterLocation)(securityScheme?.In); + Scheme = securityScheme?.Scheme; + BearerFormat = securityScheme?.BearerFormat; + Flows = new(securityScheme?.Flows); + OpenIdConnectUrl = new Uri(securityScheme?.OpenIdConnectUrl?.OriginalString); + Extensions = securityScheme?.Extensions != null ? new Dictionary(securityScheme?.Extensions) : securityScheme?.Extensions; + UnresolvedReference = securityScheme?.UnresolvedReference ?? false; + Reference = new(securityScheme?.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 875bef5c7..c0ec7114a 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; + Url = server?.Url; + Variables = server?.Variables != null ? new Dictionary(server?.Variables) : server?.Variables; + Extensions = server?.Extensions != null ? new Dictionary(server?.Extensions) : server?.Extensions; } /// 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..4e3785d4e 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; + Description = tag?.Description; + ExternalDocs = new(tag?.ExternalDocs); + Extensions = tag?.Extensions != null ? new Dictionary(tag?.Extensions) : tag?.Extensions; + UnresolvedReference = tag?.UnresolvedReference ?? false; + Reference = new(tag?.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index eb48132ad..19e231dea 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; + Namespace = xml?.Namespace; + Prefix = xml?.Prefix; + Attribute = xml?.Attribute ?? false; + Wrapped = xml?.Wrapped ?? false; + Extensions = xml?.Extensions != null ? new Dictionary(xml?.Extensions) : xml?.Extensions; } /// 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; } /// From 0eb6becf41ccc0adaae4da41804048c22b3e7952 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 12 Aug 2022 15:50:58 +0300 Subject: [PATCH 2/4] Defaults to false for bool property --- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 45d520b3a..8b073244c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -288,7 +288,7 @@ public OpenApiSchema(OpenApiSchema schema) ExternalDocs = new(schema?.ExternalDocs); Deprecated = schema?.Deprecated ?? false; Xml = new(schema?.Xml); - UnresolvedReference = schema?.UnresolvedReference; + UnresolvedReference = schema?.UnresolvedReference ?? false; Reference = new(schema?.Reference); } From 9c5aa0059adc9a5d14c1488ccb310c3a6e3d6408 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 12 Aug 2022 16:07:02 +0300 Subject: [PATCH 3/4] Resort to default is enum value is null --- src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index 1bc427e9a..8b85e4575 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -84,10 +84,10 @@ public OpenApiSecurityScheme() {} /// public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) { - Type = (SecuritySchemeType)(securityScheme?.Type); + Type = securityScheme?.Type ?? default; Description = securityScheme?.Description; Name = securityScheme?.Name; - In = (ParameterLocation)(securityScheme?.In); + In = securityScheme?.In ?? default; Scheme = securityScheme?.Scheme; BearerFormat = securityScheme?.BearerFormat; Flows = new(securityScheme?.Flows); From 17dfe3c6fa32b634d846bf26b73f7d09fe800f21 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 12 Aug 2022 18:12:35 +0300 Subject: [PATCH 4/4] Address PR feedback --- .../Models/OpenApiCallback.cs | 8 +-- .../Models/OpenApiComponents.cs | 20 +++--- .../Models/OpenApiContact.cs | 8 +-- .../Models/OpenApiDiscriminator.cs | 4 +- .../Models/OpenApiDocument.cs | 18 ++--- .../Models/OpenApiEncoding.cs | 12 ++-- .../Models/OpenApiExample.cs | 12 ++-- .../Models/OpenApiExternalDocs.cs | 6 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 26 +++---- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 14 ++-- .../Models/OpenApiLicense.cs | 6 +- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 18 ++--- .../Models/OpenApiMediaType.cs | 8 +-- .../Models/OpenApiOAuthFlow.cs | 10 +-- .../Models/OpenApiOAuthFlows.cs | 10 +-- .../Models/OpenApiOperation.cs | 22 +++--- .../Models/OpenApiParameter.cs | 30 ++++---- .../Models/OpenApiPathItem.cs | 16 ++--- .../Models/OpenApiRequestBody.cs | 12 ++-- .../Models/OpenApiResponse.cs | 14 ++-- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 70 +++++++++---------- .../Models/OpenApiSecurityScheme.cs | 22 +++--- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 8 +-- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 12 ++-- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 12 ++-- 25 files changed, 199 insertions(+), 199 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index beed0ad06..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 ?? false; - Reference = new(callback?.Reference); - Extensions = callback?.Extensions != null ? new Dictionary(callback?.Extensions) : 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 7e4a481ac..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 = components?.Schemas != null ? new Dictionary(components?.Schemas) : components?.Schemas; - Responses = components?.Responses != null ? new Dictionary(components?.Responses) : components?.Responses; - Parameters = components?.Parameters != null ? new Dictionary(components?.Parameters) : components?.Parameters; - Examples = components?.Examples != null ? new Dictionary(components?.Examples) : components?.Examples; - RequestBodies = components?.RequestBodies != null ? new Dictionary(components?.RequestBodies) : components?.RequestBodies; - Headers = components?.Headers != null ? new Dictionary(components?.Headers) : components?.Headers; - SecuritySchemes = components?.SecuritySchemes != null ? new Dictionary(components?.SecuritySchemes) : components?.SecuritySchemes; - Links = components?.Links != null ? new Dictionary(components?.Links) : components?.Links; - Callbacks = components?.Callbacks != null ? new Dictionary(components?.Callbacks) : components?.Callbacks; - Extensions = components?.Extensions != null ? new Dictionary(components?.Extensions) : 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 28001e928..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 = contact?.Url; - Email = contact?.Email; - Extensions = contact?.Extensions != null ? new Dictionary(contact?.Extensions) : 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 f39819a0a..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 = discriminator?.Mapping != null ? new Dictionary(discriminator?.Mapping) : 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 21c5f2e53..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 = document?.Servers != null ? new List(document?.Servers) : document?.Servers; - Paths = new(document?.Paths); - Components = new(document?.Components); - SecurityRequirements = document?.SecurityRequirements != null ? new List(document?.SecurityRequirements) : document?.SecurityRequirements; - Tags = document?.Tags != null ? new List(document?.Tags) : document?.Tags; - ExternalDocs = new(document?.ExternalDocs); - Extensions = document?.Extensions != null ? new Dictionary(document?.Extensions) : 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 bc154e8fb..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 = encoding?.Headers != null ? new Dictionary(encoding?.Headers) : encoding?.Headers; - Style = encoding?.Style; - Explode = encoding?.Explode ?? false; - AllowReserved = encoding?.AllowReserved ?? false; - Extensions = encoding?.Extensions != null ? new Dictionary(encoding?.Extensions) : 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 b9bfc031a..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; + Summary = example?.Summary ?? Summary; + Description = example?.Description ?? Description; Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); - ExternalValue = example?.ExternalValue; - Extensions = example?.Extensions != null ? new Dictionary(example?.Extensions) : example?.Extensions; - Reference = new(example?.Reference); - UnresolvedReference = example?.UnresolvedReference ?? false; + 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 040b7d674..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 = externalDocs?.Url != null ? new Uri(externalDocs?.Url?.OriginalString) : externalDocs?.Url; - Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs?.Extensions) : 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 a7ca745d2..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 ?? false; - Reference = new(header?.Reference); - Description = header?.Description; - Required = header?.Required ?? false; - Deprecated = header?.Deprecated ?? false; - AllowEmptyValue = header?.AllowEmptyValue ?? false; - Style = header?.Style; - Explode = header?.Explode ?? false; - AllowReserved = header?.AllowReserved ?? false; - Schema = new(header?.Schema); + 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) : header?.Examples; - Content = header?.Content != null ? new Dictionary(header?.Content) : header?.Content; - Extensions = header?.Extensions != null ? new Dictionary(header?.Extensions) : header?.Extensions; + 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 1dcae81e2..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 = info?.Extensions != null ? new Dictionary(info?.Extensions) : 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 399441b46..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 = license?.Url != null ? new Uri(license?.Url?.OriginalString) : license?.Url; - Extensions = license?.Extensions != null ? new Dictionary(license?.Extensions) : 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 3a5a72c1d..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 = link?.Extensions != null ? new Dictionary(link?.Extensions) : link?.Extensions; - UnresolvedReference = link?.UnresolvedReference ?? false; - 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 b6245f202..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); + Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); - Examples = mediaType?.Examples != null ? new Dictionary(mediaType?.Examples) : mediaType?.Examples; - Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType?.Encoding) : mediaType?.Encoding; - Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType?.Extensions) : mediaType?.Extensions; + 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 f5a9b46c4..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 = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow?.AuthorizationUrl?.OriginalString) : oAuthFlow?.AuthorizationUrl; - TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow?.TokenUrl?.OriginalString) : oAuthFlow?.TokenUrl; - RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow?.RefreshUrl?.OriginalString) : oAuthFlow?.RefreshUrl; - Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow?.Scopes) : oAuthFlow?.Scopes; - Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow?.Extensions) : 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 d286c7641..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 = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows?.Extensions) : 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 e7f8b8910..ba0af7317 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -117,18 +117,18 @@ 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 = operation?.Parameters != null ? new List(operation?.Parameters) : operation?.Parameters; + 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 = new(operation?.Responses); - Callbacks = operation?.Callbacks != null ? new Dictionary(operation?.Callbacks) : operation?.Callbacks; - Deprecated = operation?.Deprecated ?? false; - Security = operation?.Security != null ? new List(operation?.Security) : operation?.Security; - Servers = operation?.Servers != null ? new List(operation?.Servers) : operation?.Servers; - Extensions = operation?.Extensions != null ? new Dictionary(operation?.Extensions) : operation?.Extensions; + 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 7a429ef0a..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 ?? false; - Reference = new(parameter?.Reference); - Name = parameter?.Name; - In = parameter?.In; - Description = parameter?.Description; - Required = parameter?.Required ?? false; - Style = parameter?.Style; - Explode = parameter?.Explode ?? false; - AllowReserved = parameter?.AllowReserved ?? false; - Schema = new(parameter?.Schema); - Examples = parameter?.Examples != null ? new Dictionary(parameter?.Examples) : parameter?.Examples; + 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) : parameter?.Content; - Extensions = parameter?.Extensions != null ? new Dictionary(parameter?.Extensions) : parameter?.Extensions; - AllowEmptyValue = parameter?.AllowEmptyValue ?? false; - Deprecated = parameter?.Deprecated ?? false; + 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 89313be87..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 = pathItem?.Operations != null ? new Dictionary(pathItem?.Operations) : pathItem?.Operations; - Servers = pathItem?.Servers != null ? new List(pathItem?.Servers) : pathItem?.Servers; - Parameters = pathItem?.Parameters != null ? new List(pathItem?.Parameters) : pathItem?.Parameters; - Extensions = pathItem?.Extensions != null ? new Dictionary(pathItem?.Extensions) : pathItem?.Extensions; - UnresolvedReference = pathItem?.UnresolvedReference ?? false; - 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/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 6e7bdaf77..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 ?? false; - Reference = new(requestBody?.Reference); - Description = requestBody?.Description; - Required = requestBody?.Required ?? false; - Content = requestBody?.Content != null ? new Dictionary(requestBody?.Content) : requestBody?.Content; - Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody?.Extensions) : 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 46b7b63b0..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 = response?.Headers != null ? new Dictionary(response?.Headers) : response?.Headers; - Content = response?.Content != null ? new Dictionary(response?.Content) : response?.Content; - Links = response?.Links != null ? new Dictionary(response?.Links) : response?.Links; - Extensions = response?.Extensions != null ? new Dictionary(response?.Extensions) : response?.Extensions; - UnresolvedReference = response?.UnresolvedReference ?? false; - 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 8b073244c..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; + 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 ?? false; - WriteOnly = schema?.WriteOnly ?? false; - AllOf = schema?.AllOf != null ? new List(schema?.AllOf) : schema?.AllOf; - OneOf = schema?.OneOf != null ? new List(schema?.OneOf) : schema?.OneOf; - AnyOf = schema?.AnyOf != null ? new List(schema?.AnyOf) : schema?.AnyOf; - Not = new(schema?.Not); - Required = schema?.Required != null ? new HashSet(schema?.Required) : schema?.Required; - Items = new(schema?.Items); - MaxItems = schema?.MaxItems; - MinItems = schema?.MinItems; - UniqueItems = schema?.UniqueItems; - Properties = schema?.Properties != null ? new Dictionary(schema?.Properties) : schema?.Properties; - MaxProperties = schema?.MaxProperties; - MinProperties = schema?.MinProperties; - AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? false; + 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 = new(schema?.Discriminator); + Discriminator = schema?.Discriminator != null ? new(schema?.Discriminator) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema?.Example); - Enum = schema?.Enum != null ? new List(schema?.Enum) : schema?.Enum; - Nullable = schema?.Nullable ?? false; - ExternalDocs = new(schema?.ExternalDocs); - Deprecated = schema?.Deprecated ?? false; - Xml = new(schema?.Xml); - UnresolvedReference = schema?.UnresolvedReference ?? false; - Reference = new(schema?.Reference); + 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 8b85e4575..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 ?? default; - Description = securityScheme?.Description; - Name = securityScheme?.Name; - In = securityScheme?.In ?? default; - Scheme = securityScheme?.Scheme; - BearerFormat = securityScheme?.BearerFormat; - Flows = new(securityScheme?.Flows); - OpenIdConnectUrl = new Uri(securityScheme?.OpenIdConnectUrl?.OriginalString); - Extensions = securityScheme?.Extensions != null ? new Dictionary(securityScheme?.Extensions) : securityScheme?.Extensions; - UnresolvedReference = securityScheme?.UnresolvedReference ?? false; - 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 c0ec7114a..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 = server?.Variables != null ? new Dictionary(server?.Variables) : server?.Variables; - Extensions = server?.Extensions != null ? new Dictionary(server?.Extensions) : 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/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 4e3785d4e..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 = tag?.Extensions != null ? new Dictionary(tag?.Extensions) : tag?.Extensions; - UnresolvedReference = tag?.UnresolvedReference ?? false; - 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 19e231dea..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 ?? false; - Wrapped = xml?.Wrapped ?? false; - Extensions = xml?.Extensions != null ? new Dictionary(xml?.Extensions) : 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; } ///