From b0bf2ae84d9a846bf94e9780e253aa42139feae7 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 11 May 2022 11:15:35 +0300 Subject: [PATCH 01/13] Adds a copy constructor for all models and cleans up code --- .../Models/OpenApiCallback.cs | 16 ++++++ .../Models/OpenApiComponents.cs | 22 ++++++++ .../Models/OpenApiContact.cs | 16 ++++++ .../Models/OpenApiDiscriminator.cs | 14 ++++++ .../Models/OpenApiDocument.cs | 23 ++++++++- .../Models/OpenApiEncoding.cs | 18 +++++++ src/Microsoft.OpenApi/Models/OpenApiError.cs | 9 ++++ .../Models/OpenApiExample.cs | 19 +++++++ .../Models/OpenApiExternalDocs.cs | 15 ++++++ src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 26 ++++++++++ src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 19 +++++++ .../Models/OpenApiLicense.cs | 15 ++++++ src/Microsoft.OpenApi/Models/OpenApiLink.cs | 21 ++++++++ .../Models/OpenApiMediaType.cs | 17 +++++++ .../Models/OpenApiOAuthFlow.cs | 17 +++++++ .../Models/OpenApiOAuthFlows.cs | 18 +++++++ .../Models/OpenApiOperation.cs | 25 ++++++++++ .../Models/OpenApiParameter.cs | 28 +++++++++++ .../Models/OpenApiPathItem.cs | 20 ++++++++ .../Models/OpenApiReference.cs | 16 ++++++ .../Models/OpenApiRequestBody.cs | 18 +++++++ .../Models/OpenApiResponse.cs | 19 +++++++ src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 50 +++++++++++++++++++ .../Models/OpenApiSecurityScheme.cs | 23 +++++++++ src/Microsoft.OpenApi/Models/OpenApiServer.cs | 16 ++++++ .../Models/OpenApiServerVariable.cs | 16 ++++++ src/Microsoft.OpenApi/Models/OpenApiTag.cs | 18 +++++++ src/Microsoft.OpenApi/Models/OpenApiXml.cs | 18 +++++++ .../V2Tests/OpenApiDocumentTests.cs | 9 ---- 29 files changed, 550 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 57aa3c888..57bdc3b73 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -35,6 +35,22 @@ public class OpenApiCallback : IOpenApiSerializable, IOpenApiReferenceable, IOpe /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiCallback() { } + + /// + /// Initializes a copy of an object + /// + public OpenApiCallback(OpenApiCallback callback) + { + PathItems = callback.PathItems; + UnresolvedReference = callback.UnresolvedReference; + Reference = callback.Reference; + Extensions = callback.Extensions; + } + /// /// Add a into the . /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index cd8cdae74..176f1277f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -68,6 +68,28 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiComponents() { } + + /// + /// Initializes a copy of an object + /// + public OpenApiComponents(OpenApiComponents components) + { + Schemas = components.Schemas; + Responses = components.Responses; + Parameters = components.Parameters; + Examples = components.Examples; + RequestBodies = components.RequestBodies; + Headers = components.Headers; + SecuritySchemes = components.SecuritySchemes; + Links = components.Links; + Callbacks = components.Callbacks; + Extensions = components.Extensions; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 848560ead..c26e6512b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -35,6 +35,22 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiContact() { } + + /// + /// Initializes a copy of an instance + /// + public OpenApiContact(OpenApiContact contact) + { + Name = contact.Name; + Url = contact.Url; + Email = contact.Email; + Extensions = contact.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index a0739dc25..b8caf54bb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -22,6 +22,20 @@ public class OpenApiDiscriminator : IOpenApiSerializable /// public IDictionary Mapping { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiDiscriminator() { } + + /// + /// Initializes a copy of an instance + /// + public OpenApiDiscriminator(OpenApiDiscriminator discriminator) + { + PropertyName = discriminator.PropertyName; + Mapping = discriminator.Mapping; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 59b8da16c..e8ad85c81 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Services; @@ -64,6 +62,27 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiDocument() {} + + /// + /// Initializes a copy of an an object + /// + public OpenApiDocument(OpenApiDocument document) + { + Workspace = document.Workspace; + Info = document.Info; + Servers = document.Servers; + Paths = document.Paths; + Components = document.Components; + SecurityRequirements = document.SecurityRequirements; + Tags = document.Tags; + ExternalDocs = document.ExternalDocs; + Extensions = document.Extensions; + } + /// /// Serialize to the latest patch of OpenAPI object V3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 0d02c384e..0757c5f8d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -53,6 +53,24 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiEncoding() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiEncoding(OpenApiEncoding encoding) + { + ContentType = encoding.ContentType; + Headers = encoding.Headers; + Style = encoding.Style; + Explode = encoding.Explode; + AllowReserved = encoding.AllowReserved; + Extensions = encoding.Extensions; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiError.cs b/src/Microsoft.OpenApi/Models/OpenApiError.cs index 98bf7ec82..82f2a14df 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiError.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiError.cs @@ -26,6 +26,15 @@ public OpenApiError(string pointer, string message) Message = message; } + /// + /// Initializes a copy of an object + /// + public OpenApiError(OpenApiError error) + { + Pointer = error.Pointer; + Message = error.Message; + } + /// /// Message explaining the error. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index d4c268584..2da67941f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -54,6 +54,25 @@ public class OpenApiExample : IOpenApiSerializable, IOpenApiReferenceable, IOpen /// public bool UnresolvedReference { get; set; } = false; + /// + /// Parameter-less constructor + /// + public OpenApiExample() {} + + /// + /// Initializes a copy of object + /// + public OpenApiExample(OpenApiExample example) + { + Summary = example.Summary; + Description = example.Description; + Value = example.Value; + ExternalValue = example.ExternalValue; + Extensions = example.Extensions; + Reference = example.Reference; + UnresolvedReference = example.UnresolvedReference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index a47fb9906..412d773bb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -29,6 +29,21 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiExternalDocs() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) + { + Description = externalDocs.Description; + Url = externalDocs.Url; + Extensions = externalDocs.Extensions; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index e8576a0ca..ed782e7fd 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -86,6 +86,32 @@ public class OpenApiHeader : IOpenApiSerializable, IOpenApiReferenceable, IOpenA /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiHeader() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiHeader(OpenApiHeader header) + { + UnresolvedReference = header.UnresolvedReference; + Reference = header.Reference; + Description = header.Description; + Required = header.Required; + Deprecated = header.Deprecated; + AllowEmptyValue = header.AllowEmptyValue; + Style = header.Style; + Explode = header.Explode; + AllowReserved = header.AllowReserved; + Schema = header.Schema; + Example = header.Example; + Examples = header.Examples; + Content = header.Content; + Extensions = header.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 17364ba3b..84bb63a3e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -49,6 +49,25 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiInfo() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiInfo(OpenApiInfo info) + { + Title = info.Title; + Description = info.Description; + Version = info.Version; + TermsOfService = info.TermsOfService; + Contact = info.Contact; + License = info.License; + Extensions = info.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 0de7540c8..eb4ce5e02 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -29,6 +29,21 @@ public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiLicense() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiLicense(OpenApiLicense license) + { + Name = license.Name; + Url = license.Url; + Extensions = license.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index f5acb0d3f..68a8aa9fd 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -61,6 +61,27 @@ public class OpenApiLink : IOpenApiSerializable, IOpenApiReferenceable, IOpenApi /// public OpenApiReference Reference { get; set; } + /// + /// Parameterless constructor + /// + public OpenApiLink() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiLink(OpenApiLink link) + { + OperationRef = link.OperationRef; + OperationId = link.OperationId; + Parameters = link.Parameters; + RequestBody = link.RequestBody; + Description = link.Description; + Server = link.Server; + Extensions = link.Extensions; + UnresolvedReference = link.UnresolvedReference; + Reference = link.Reference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 414f46b30..0982800e2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -43,6 +43,23 @@ public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiMediaType() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiMediaType(OpenApiMediaType mediaType) + { + Schema = mediaType.Schema; + Example = mediaType.Example; + Examples = mediaType.Examples; + Encoding = mediaType.Encoding; + Extensions = mediaType.Extensions; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index e478944aa..a69562207 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -41,6 +41,23 @@ public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiOAuthFlow() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) + { + AuthorizationUrl = oAuthFlow.AuthorizationUrl; + TokenUrl = oAuthFlow.TokenUrl; + RefreshUrl = oAuthFlow.RefreshUrl; + Scopes = oAuthFlow.Scopes; + Extensions = oAuthFlow.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index fa2db10db..f16afa961 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -38,6 +38,24 @@ public class OpenApiOAuthFlows : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiOAuthFlows() {} + + /// + /// Initializes a copy of an object + /// + /// + public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) + { + Implicit = oAuthFlows.Implicit; + Password = oAuthFlows.Password; + ClientCredentials = oAuthFlows.ClientCredentials; + AuthorizationCode = oAuthFlows.AuthorizationCode; + Extensions = oAuthFlows.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index f17f81328..f56674261 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -106,6 +106,31 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiOperation() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiOperation(OpenApiOperation operation) + { + Tags = operation.Tags; + Summary = operation.Summary; + Description = operation.Description; + ExternalDocs = operation.ExternalDocs; + OperationId = operation.OperationId; + Parameters = operation.Parameters; + RequestBody = operation.RequestBody; + Responses = operation.Responses; + Callbacks = operation.Callbacks; + Deprecated = operation.Deprecated; + Security = operation.Security; + Servers = operation.Servers; + Extensions = operation.Extensions; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 12f37f61a..c1946ab35 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -136,6 +136,34 @@ public bool Explode /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// A parameterless constructor + /// + public OpenApiParameter() {} + + /// + /// Initializes a clone instance of object + /// + public OpenApiParameter(OpenApiParameter parameter) + { + UnresolvedReference = parameter.UnresolvedReference; + Reference = parameter.Reference; + Name = parameter.Name; + In = parameter.In; + Description = parameter.Description; + Required = parameter.Required; + Style = parameter.Style; + Explode = parameter.Explode; + AllowReserved = parameter.AllowReserved; + Schema = parameter.Schema; + Examples = parameter.Examples; + Example = parameter.Example; + Content = parameter.Content; + Extensions = parameter.Extensions; + AllowEmptyValue = parameter.AllowEmptyValue; + Deprecated = parameter.Deprecated; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 375f1f034..cc824b184 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -65,6 +65,26 @@ public void AddOperation(OperationType operationType, OpenApiOperation operation Operations[operationType] = operation; } + /// + /// Parameterless constructor + /// + public OpenApiPathItem() {} + + /// + /// Initializes a clone of an object + /// + public OpenApiPathItem(OpenApiPathItem pathItem) + { + Summary = pathItem.Summary; + Description = pathItem.Description; + Operations = pathItem.Operations; + Servers = pathItem.Servers; + Parameters = pathItem.Parameters; + Extensions = pathItem.Extensions; + UnresolvedReference = pathItem.UnresolvedReference; + Reference = pathItem.Reference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index 3f1370800..93cc0578f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -112,6 +112,22 @@ public string ReferenceV2 } } + /// + /// Parameterless constructor + /// + public OpenApiReference() {} + + /// + /// Initializes a copy instance of the object + /// + public OpenApiReference(OpenApiReference reference) + { + ExternalResource = reference.ExternalResource; + Type = reference.Type; + Id = reference.Id; + HostDocument = reference.HostDocument; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 8a65f1fde..9ee0d5247 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -45,6 +45,24 @@ public class OpenApiRequestBody : IOpenApiSerializable, IOpenApiReferenceable, I /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameter-less constructor + /// + public OpenApiRequestBody() { } + + /// + /// Initializes a copy instance of an object + /// + public OpenApiRequestBody(OpenApiRequestBody requestBody) + { + UnresolvedReference = requestBody.UnresolvedReference; + Reference = requestBody.Reference; + Description = requestBody.Description; + Required = requestBody.Required; + Content = requestBody.Content; + Extensions = requestBody.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 0a31ca0a4..637e23835 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -51,6 +51,25 @@ public class OpenApiResponse : IOpenApiSerializable, IOpenApiReferenceable, IOpe /// public OpenApiReference Reference { get; set; } + /// + /// Parameterless constructor + /// + public OpenApiResponse() {} + + /// + /// Initializes a copy of object + /// + public OpenApiResponse(OpenApiResponse response) + { + Description = response.Description; + Headers = response.Headers; + Content = response.Content; + Links = response.Links; + Extensions = response.Extensions; + UnresolvedReference = response.UnresolvedReference; + Reference = response.Reference; + } + /// /// Serialize to Open Api v3.0. /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 036222261..6934f2eda 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -242,6 +242,56 @@ public class OpenApiSchema : IOpenApiSerializable, IOpenApiReferenceable, IEffec /// public OpenApiReference Reference { get; set; } + /// + /// Parameterless constructor + /// + public OpenApiSchema() {} + + /// + /// Initializes a copy of object + /// + 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 = schema.Default; + ReadOnly = schema.ReadOnly; + WriteOnly = schema.WriteOnly; + AllOf = schema.AllOf; + OneOf = schema.OneOf; + AnyOf = schema.AnyOf; + Not = schema.Not; + Required = schema.Required; + Items = schema.Items; + MaxItems = schema.MaxItems; + MinItems = schema.MinItems; + UniqueItems = schema.UniqueItems; + Properties = schema.Properties; + MaxProperties = schema.MaxProperties; + MinProperties = schema.MinProperties; + AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; + AdditionalProperties = schema.AdditionalProperties; + Discriminator = schema.Discriminator; + Example = schema.Example; + Enum = schema.Enum; + Nullable = schema.Nullable; + ExternalDocs = schema.ExternalDocs; + Deprecated = schema.Deprecated; + Xml = schema.Xml; + UnresolvedReference = schema.UnresolvedReference; + Reference = schema.Reference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index 902ce19bc..eaba8b40d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -74,6 +74,29 @@ public class OpenApiSecurityScheme : IOpenApiSerializable, IOpenApiReferenceable /// public OpenApiReference Reference { get; set; } + /// + /// Parameterless constructor + /// + public OpenApiSecurityScheme() {} + + /// + /// Initializes a copy of object + /// + public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) + { + Type = securityScheme.Type; + Description = securityScheme.Description; + Name = securityScheme.Name; + In = securityScheme.In; + Scheme = securityScheme.Scheme; + BearerFormat = securityScheme.BearerFormat; + Flows = securityScheme.Flows; + OpenIdConnectUrl = securityScheme.OpenIdConnectUrl; + Extensions = securityScheme.Extensions; + UnresolvedReference = securityScheme.UnresolvedReference; + Reference = securityScheme.Reference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index ea988ec13..0ae3f83e9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -36,6 +36,22 @@ public class OpenApiServer : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiServer() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiServer(OpenApiServer server) + { + Description = server.Description; + Url = server.Url; + Variables = server.Variables; + Extensions = server.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 8ae39a04c..8813ab69b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -34,6 +34,22 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiServerVariable() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiServerVariable(OpenApiServerVariable serverVariable) + { + Description = serverVariable.Description; + Default = serverVariable.Default; + Enum = serverVariable.Enum; + Extensions = serverVariable.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 4d743a13a..ed6f916b5 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -43,6 +43,24 @@ public class OpenApiTag : IOpenApiSerializable, IOpenApiReferenceable, IOpenApiE /// public OpenApiReference Reference { get; set; } + /// + /// Parameterless constructor + /// + public OpenApiTag() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiTag(OpenApiTag tag) + { + Name = tag.Name; + Description = tag.Description; + ExternalDocs = tag.ExternalDocs; + Extensions = tag.Extensions; + UnresolvedReference = tag.UnresolvedReference; + Reference = tag.Reference; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index 59218970f..70e438b1c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -46,6 +46,24 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible /// public IDictionary Extensions { get; set; } = new Dictionary(); + /// + /// Parameterless constructor + /// + public OpenApiXml() {} + + /// + /// Initializes a copy of an object + /// + public OpenApiXml(OpenApiXml xml) + { + Name = xml.Name; + Namespace = xml.Namespace; + Prefix = xml.Prefix; + Attribute = xml.Attribute; + Wrapped = xml.Wrapped; + Extensions = xml.Extensions; + } + /// /// Serialize to Open Api v3.0 /// diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index 57593a79e..39bc0db80 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -174,15 +174,6 @@ public void ShouldParseProducesInAnyOrder() }, Items = new OpenApiSchema() { - //Properties = new Dictionary() - // { - // { "id", new OpenApiSchema() - // { - // Type = "string", - // Description = "Item identifier." - // } - // } - // }, Reference = new OpenApiReference() { Type = ReferenceType.Schema, From c61e1cbf8cb8315c3901d56eb2bf090b87a12209 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 11 May 2022 12:39:52 +0300 Subject: [PATCH 02/13] Update public Api interface --- .../PublicApi/PublicApi.approved.txt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 02400ddd7..f753292e1 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -323,6 +323,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiCallback : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiCallback() { } + public OpenApiCallback(Microsoft.OpenApi.Models.OpenApiCallback callback) { } public System.Collections.Generic.IDictionary Extensions { get; set; } public System.Collections.Generic.Dictionary PathItems { get; set; } public Microsoft.OpenApi.Models.OpenApiReference Reference { get; set; } @@ -337,6 +338,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiComponents : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiComponents() { } + public OpenApiComponents(Microsoft.OpenApi.Models.OpenApiComponents components) { } public System.Collections.Generic.IDictionary Callbacks { get; set; } public System.Collections.Generic.IDictionary Examples { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -481,6 +483,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiContact : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiContact() { } + public OpenApiContact(Microsoft.OpenApi.Models.OpenApiContact contact) { } public string Email { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public string Name { get; set; } @@ -491,6 +494,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiDiscriminator : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiDiscriminator() { } + public OpenApiDiscriminator(Microsoft.OpenApi.Models.OpenApiDiscriminator discriminator) { } public System.Collections.Generic.IDictionary Mapping { get; set; } public string PropertyName { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -499,6 +503,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiDocument : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiDocument() { } + public OpenApiDocument(Microsoft.OpenApi.Models.OpenApiDocument document) { } public Microsoft.OpenApi.Models.OpenApiComponents Components { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; set; } @@ -516,6 +521,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiEncoding : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiEncoding() { } + public OpenApiEncoding(Microsoft.OpenApi.Models.OpenApiEncoding encoding) { } public bool? AllowReserved { get; set; } public string ContentType { get; set; } public bool? Explode { get; set; } @@ -528,6 +534,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiError { public OpenApiError(Microsoft.OpenApi.Exceptions.OpenApiException exception) { } + public OpenApiError(Microsoft.OpenApi.Models.OpenApiError error) { } public OpenApiError(string pointer, string message) { } public string Message { get; set; } public string Pointer { get; set; } @@ -536,6 +543,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiExample : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiExample() { } + public OpenApiExample(Microsoft.OpenApi.Models.OpenApiExample example) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public string ExternalValue { get; set; } @@ -560,6 +568,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiExternalDocs : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiExternalDocs() { } + public OpenApiExternalDocs(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public System.Uri Url { get; set; } @@ -569,6 +578,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiHeader : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiHeader() { } + public OpenApiHeader(Microsoft.OpenApi.Models.OpenApiHeader header) { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } public System.Collections.Generic.IDictionary Content { get; set; } @@ -592,6 +602,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiInfo : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiInfo() { } + public OpenApiInfo(Microsoft.OpenApi.Models.OpenApiInfo info) { } public Microsoft.OpenApi.Models.OpenApiContact Contact { get; set; } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -605,6 +616,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiLicense : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiLicense() { } + public OpenApiLicense(Microsoft.OpenApi.Models.OpenApiLicense license) { } public System.Collections.Generic.IDictionary Extensions { get; set; } public string Name { get; set; } public System.Uri Url { get; set; } @@ -614,6 +626,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiLink : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiLink() { } + public OpenApiLink(Microsoft.OpenApi.Models.OpenApiLink link) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public string OperationId { get; set; } @@ -632,6 +645,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiMediaType : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiMediaType() { } + public OpenApiMediaType(Microsoft.OpenApi.Models.OpenApiMediaType mediaType) { } public System.Collections.Generic.IDictionary Encoding { get; set; } public Microsoft.OpenApi.Any.IOpenApiAny Example { get; set; } public System.Collections.Generic.IDictionary Examples { get; set; } @@ -643,6 +657,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiOAuthFlow : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiOAuthFlow() { } + public OpenApiOAuthFlow(Microsoft.OpenApi.Models.OpenApiOAuthFlow oAuthFlow) { } public System.Uri AuthorizationUrl { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public System.Uri RefreshUrl { get; set; } @@ -654,6 +669,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiOAuthFlows : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiOAuthFlows() { } + public OpenApiOAuthFlows(Microsoft.OpenApi.Models.OpenApiOAuthFlows oAuthFlows) { } public Microsoft.OpenApi.Models.OpenApiOAuthFlow AuthorizationCode { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlow ClientCredentials { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -666,6 +682,7 @@ namespace Microsoft.OpenApi.Models { public const bool DeprecatedDefault = false; public OpenApiOperation() { } + public OpenApiOperation(Microsoft.OpenApi.Models.OpenApiOperation operation) { } public System.Collections.Generic.IDictionary Callbacks { get; set; } public bool Deprecated { get; set; } public string Description { get; set; } @@ -685,6 +702,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiParameter : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiParameter() { } + public OpenApiParameter(Microsoft.OpenApi.Models.OpenApiParameter parameter) { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } public System.Collections.Generic.IDictionary Content { get; set; } @@ -710,6 +728,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiPathItem : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiPathItem() { } + public OpenApiPathItem(Microsoft.OpenApi.Models.OpenApiPathItem pathItem) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public System.Collections.Generic.IDictionary Operations { get; set; } @@ -732,6 +751,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiReference : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiReference() { } + public OpenApiReference(Microsoft.OpenApi.Models.OpenApiReference reference) { } public string ExternalResource { get; set; } public Microsoft.OpenApi.Models.OpenApiDocument HostDocument { get; set; } public string Id { get; set; } @@ -746,6 +766,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiRequestBody : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiRequestBody() { } + public OpenApiRequestBody(Microsoft.OpenApi.Models.OpenApiRequestBody requestBody) { } public System.Collections.Generic.IDictionary Content { get; set; } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -761,6 +782,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiResponse : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiResponse() { } + public OpenApiResponse(Microsoft.OpenApi.Models.OpenApiResponse response) { } public System.Collections.Generic.IDictionary Content { get; set; } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -781,6 +803,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiSchema : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiSchema() { } + public OpenApiSchema(Microsoft.OpenApi.Models.OpenApiSchema schema) { } public Microsoft.OpenApi.Models.OpenApiSchema AdditionalProperties { get; set; } public bool AdditionalPropertiesAllowed { get; set; } public System.Collections.Generic.IList AllOf { get; set; } @@ -835,6 +858,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiSecurityScheme : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiSecurityScheme() { } + public OpenApiSecurityScheme(Microsoft.OpenApi.Models.OpenApiSecurityScheme securityScheme) { } public string BearerFormat { get; set; } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } @@ -854,6 +878,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiServer : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiServer() { } + public OpenApiServer(Microsoft.OpenApi.Models.OpenApiServer server) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public string Url { get; set; } @@ -864,6 +889,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiServerVariable : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiServerVariable() { } + public OpenApiServerVariable(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } public string Default { get; set; } public string Description { get; set; } public System.Collections.Generic.List Enum { get; set; } @@ -874,6 +900,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiTag : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiTag() { } + public OpenApiTag(Microsoft.OpenApi.Models.OpenApiTag tag) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; set; } @@ -888,6 +915,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiXml : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiXml() { } + public OpenApiXml(Microsoft.OpenApi.Models.OpenApiXml xml) { } public bool Attribute { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public string Name { get; set; } From eae3641a6b3ad6ec0ad3f524e9eb23ad7464d3ad Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 4 Jul 2022 19:26:17 +0300 Subject: [PATCH 03/13] Create new object instances for copying purposes --- .../Models/OpenApiCallback.cs | 6 ++--- .../Models/OpenApiComponents.cs | 20 +++++++------- .../Models/OpenApiContact.cs | 2 +- .../Models/OpenApiDiscriminator.cs | 2 +- .../Models/OpenApiDocument.cs | 18 ++++++------- .../Models/OpenApiEncoding.cs | 4 +-- .../Models/OpenApiExample.cs | 4 +-- .../Models/OpenApiExternalDocs.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 10 +++---- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 6 ++--- .../Models/OpenApiLicense.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 10 +++---- .../Models/OpenApiMediaType.cs | 8 +++--- .../Models/OpenApiOAuthFlow.cs | 4 +-- .../Models/OpenApiOAuthFlows.cs | 10 +++---- .../Models/OpenApiOperation.cs | 18 ++++++------- .../Models/OpenApiParameter.cs | 10 +++---- .../Models/OpenApiPathItem.cs | 10 +++---- src/Microsoft.OpenApi/Models/OpenApiPaths.cs | 3 +++ .../Models/OpenApiReference.cs | 2 +- .../Models/OpenApiRequestBody.cs | 6 ++--- .../Models/OpenApiResponse.cs | 10 +++---- .../Models/OpenApiResponses.cs | 4 +++ src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 26 +++++++++---------- .../Models/OpenApiSecurityScheme.cs | 6 ++--- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 4 +-- .../Models/OpenApiServerVariable.cs | 4 +-- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 6 ++--- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 2 +- .../Models/RuntimeExpressionAnyWrapper.cs | 8 ++++++ .../Services/OpenApiWorkspace.cs | 2 ++ 31 files changed, 123 insertions(+), 106 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 57bdc3b73..e9701b17c 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 = callback.PathItems; + PathItems = new(callback.PathItems); UnresolvedReference = callback.UnresolvedReference; - Reference = callback.Reference; - Extensions = callback.Extensions; + Reference = new(callback.Reference); + Extensions = new Dictionary(callback.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 176f1277f..c23e569c5 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; - Responses = components.Responses; - Parameters = components.Parameters; - Examples = components.Examples; - RequestBodies = components.RequestBodies; - Headers = components.Headers; - SecuritySchemes = components.SecuritySchemes; - Links = components.Links; - Callbacks = components.Callbacks; - Extensions = components.Extensions; + 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); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index c26e6512b..a49c80a08 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -48,7 +48,7 @@ public OpenApiContact(OpenApiContact contact) Name = contact.Name; Url = contact.Url; Email = contact.Email; - Extensions = contact.Extensions; + Extensions = new Dictionary(contact.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index b8caf54bb..e03c7d59a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -33,7 +33,7 @@ public OpenApiDiscriminator() { } public OpenApiDiscriminator(OpenApiDiscriminator discriminator) { PropertyName = discriminator.PropertyName; - Mapping = discriminator.Mapping; + Mapping = new Dictionary(discriminator.Mapping); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index e8ad85c81..44cbc71ab 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 = document.Workspace; - Info = document.Info; - Servers = document.Servers; - Paths = document.Paths; - Components = document.Components; - SecurityRequirements = document.SecurityRequirements; - Tags = document.Tags; - ExternalDocs = document.ExternalDocs; - Extensions = document.Extensions; + 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); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 0757c5f8d..533cb7e80 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -64,11 +64,11 @@ public OpenApiEncoding() {} public OpenApiEncoding(OpenApiEncoding encoding) { ContentType = encoding.ContentType; - Headers = encoding.Headers; + Headers = new Dictionary(encoding.Headers); Style = encoding.Style; Explode = encoding.Explode; AllowReserved = encoding.AllowReserved; - Extensions = encoding.Extensions; + Extensions = new Dictionary(encoding.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 2da67941f..b9d5b54bc 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -68,8 +68,8 @@ public OpenApiExample(OpenApiExample example) Description = example.Description; Value = example.Value; ExternalValue = example.ExternalValue; - Extensions = example.Extensions; - Reference = example.Reference; + Extensions = new Dictionary(example.Extensions); + Reference = new(example.Reference); UnresolvedReference = example.UnresolvedReference; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 412d773bb..afc9a5b3c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -41,7 +41,7 @@ public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { Description = externalDocs.Description; Url = externalDocs.Url; - Extensions = externalDocs.Extensions; + Extensions = new Dictionary(externalDocs.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index ed782e7fd..85a27794f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -97,7 +97,7 @@ public OpenApiHeader() {} public OpenApiHeader(OpenApiHeader header) { UnresolvedReference = header.UnresolvedReference; - Reference = header.Reference; + Reference = new(header.Reference); Description = header.Description; Required = header.Required; Deprecated = header.Deprecated; @@ -105,11 +105,11 @@ public OpenApiHeader(OpenApiHeader header) Style = header.Style; Explode = header.Explode; AllowReserved = header.AllowReserved; - Schema = header.Schema; + Schema = new(header.Schema); Example = header.Example; - Examples = header.Examples; - Content = header.Content; - Extensions = header.Extensions; + Examples = new Dictionary(header.Examples); + Content = new Dictionary(header.Content); + Extensions = new Dictionary(header.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 84bb63a3e..c5a44c448 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -63,9 +63,9 @@ public OpenApiInfo(OpenApiInfo info) Description = info.Description; Version = info.Version; TermsOfService = info.TermsOfService; - Contact = info.Contact; - License = info.License; - Extensions = info.Extensions; + Contact = new(info.Contact); + License = new(info.License); + Extensions = new Dictionary(info.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index eb4ce5e02..452f98918 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -41,7 +41,7 @@ public OpenApiLicense(OpenApiLicense license) { Name = license.Name; Url = license.Url; - Extensions = license.Extensions; + Extensions = new Dictionary(license.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 68a8aa9fd..6ba3a65fd 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -73,13 +73,13 @@ public OpenApiLink(OpenApiLink link) { OperationRef = link.OperationRef; OperationId = link.OperationId; - Parameters = link.Parameters; - RequestBody = link.RequestBody; + Parameters = new(link.Parameters); + RequestBody = new(link.RequestBody); Description = link.Description; - Server = link.Server; - Extensions = link.Extensions; + Server = new(link.Server); + Extensions = new Dictionary(link.Extensions); UnresolvedReference = link.UnresolvedReference; - Reference = link.Reference; + Reference = new(link.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 0982800e2..102c9bbbf 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 = mediaType.Schema; + Schema = new(mediaType.Schema); Example = mediaType.Example; - Examples = mediaType.Examples; - Encoding = mediaType.Encoding; - Extensions = mediaType.Extensions; + Examples = new Dictionary(mediaType.Examples); + Encoding = new Dictionary(mediaType.Encoding); + Extensions = new Dictionary(mediaType.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index a69562207..1ee47a499 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -54,8 +54,8 @@ public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) AuthorizationUrl = oAuthFlow.AuthorizationUrl; TokenUrl = oAuthFlow.TokenUrl; RefreshUrl = oAuthFlow.RefreshUrl; - Scopes = oAuthFlow.Scopes; - Extensions = oAuthFlow.Extensions; + Scopes = new Dictionary(oAuthFlow.Scopes); + Extensions = new Dictionary(oAuthFlow.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index f16afa961..973a403e0 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 = oAuthFlows.Implicit; - Password = oAuthFlows.Password; - ClientCredentials = oAuthFlows.ClientCredentials; - AuthorizationCode = oAuthFlows.AuthorizationCode; - Extensions = oAuthFlows.Extensions; + Implicit = new(oAuthFlows.Implicit); + Password = new(oAuthFlows.Password); + ClientCredentials = new(oAuthFlows.ClientCredentials); + AuthorizationCode = new(oAuthFlows.AuthorizationCode); + Extensions = new Dictionary(oAuthFlows.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index f56674261..775532684 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 = operation.Tags; + Tags = new List(operation.Tags); Summary = operation.Summary; Description = operation.Description; - ExternalDocs = operation.ExternalDocs; + ExternalDocs = new(operation.ExternalDocs); OperationId = operation.OperationId; - Parameters = operation.Parameters; - RequestBody = operation.RequestBody; - Responses = operation.Responses; - Callbacks = operation.Callbacks; + Parameters = new List(operation.Parameters); + RequestBody = new(operation.RequestBody); + Responses = new(operation.Responses); + Callbacks = new Dictionary(operation.Callbacks); Deprecated = operation.Deprecated; - Security = operation.Security; - Servers = operation.Servers; - Extensions = operation.Extensions; + Security = new List(operation.Security); + Servers = new List(operation.Servers); + Extensions = new Dictionary(operation.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index c1946ab35..94eca4a75 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -147,7 +147,7 @@ public OpenApiParameter() {} public OpenApiParameter(OpenApiParameter parameter) { UnresolvedReference = parameter.UnresolvedReference; - Reference = parameter.Reference; + Reference = new(parameter.Reference); Name = parameter.Name; In = parameter.In; Description = parameter.Description; @@ -155,11 +155,11 @@ public OpenApiParameter(OpenApiParameter parameter) Style = parameter.Style; Explode = parameter.Explode; AllowReserved = parameter.AllowReserved; - Schema = parameter.Schema; - Examples = parameter.Examples; + Schema = new(parameter.Schema); + Examples = new Dictionary(parameter.Examples); Example = parameter.Example; - Content = parameter.Content; - Extensions = parameter.Extensions; + Content = new Dictionary(parameter.Content); + Extensions = new Dictionary(parameter.Extensions); AllowEmptyValue = parameter.AllowEmptyValue; Deprecated = parameter.Deprecated; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index cc824b184..8ce83c9eb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -77,12 +77,12 @@ public OpenApiPathItem(OpenApiPathItem pathItem) { Summary = pathItem.Summary; Description = pathItem.Description; - Operations = pathItem.Operations; - Servers = pathItem.Servers; - Parameters = pathItem.Parameters; - Extensions = pathItem.Extensions; + Operations = new Dictionary(pathItem.Operations); + Servers = new List(pathItem.Servers); + Parameters = new List(pathItem.Parameters); + Extensions = new Dictionary(pathItem.Extensions); UnresolvedReference = pathItem.UnresolvedReference; - Reference = pathItem.Reference; + Reference = new(pathItem.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs index 72d0576d3..2ba371e61 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -8,5 +8,8 @@ namespace Microsoft.OpenApi.Models /// public class OpenApiPaths : OpenApiExtensibleDictionary { + public OpenApiPaths() {} + public OpenApiPaths(OpenApiPaths paths) {} + } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index 93cc0578f..9213e77bc 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -125,7 +125,7 @@ public OpenApiReference(OpenApiReference reference) ExternalResource = reference.ExternalResource; Type = reference.Type; Id = reference.Id; - HostDocument = reference.HostDocument; + HostDocument = new(reference.HostDocument); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 9ee0d5247..b82b67e8a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -56,11 +56,11 @@ public OpenApiRequestBody() { } public OpenApiRequestBody(OpenApiRequestBody requestBody) { UnresolvedReference = requestBody.UnresolvedReference; - Reference = requestBody.Reference; + Reference = new(requestBody.Reference); Description = requestBody.Description; Required = requestBody.Required; - Content = requestBody.Content; - Extensions = requestBody.Extensions; + Content = new Dictionary(requestBody.Content); + Extensions = new Dictionary(requestBody.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 637e23835..cf0c796e6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -62,12 +62,12 @@ public OpenApiResponse() {} public OpenApiResponse(OpenApiResponse response) { Description = response.Description; - Headers = response.Headers; - Content = response.Content; - Links = response.Links; - Extensions = response.Extensions; + Headers = new Dictionary(response.Headers); + Content = new Dictionary(response.Content); + Links = new Dictionary(response.Links); + Extensions = new Dictionary(response.Extensions); UnresolvedReference = response.UnresolvedReference; - Reference = response.Reference; + Reference = new(response.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs index 818bf4ced..28fe62ad4 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs @@ -8,5 +8,9 @@ namespace Microsoft.OpenApi.Models /// public class OpenApiResponses : OpenApiExtensibleDictionary { + public OpenApiResponses() { } + + public OpenApiResponses(OpenApiResponses openApiResponses) { } + } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 6934f2eda..a60cfae77 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -267,29 +267,29 @@ public OpenApiSchema(OpenApiSchema schema) Default = schema.Default; ReadOnly = schema.ReadOnly; WriteOnly = schema.WriteOnly; - AllOf = schema.AllOf; - OneOf = schema.OneOf; - AnyOf = schema.AnyOf; - Not = schema.Not; - Required = schema.Required; - Items = schema.Items; + 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 = schema.Properties; + Properties = new Dictionary(schema.Properties); MaxProperties = schema.MaxProperties; MinProperties = schema.MinProperties; AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; - AdditionalProperties = schema.AdditionalProperties; - Discriminator = schema.Discriminator; + AdditionalProperties = new(schema.AdditionalProperties); + Discriminator = new(schema.Discriminator); Example = schema.Example; - Enum = schema.Enum; + Enum = new List(schema.Enum); Nullable = schema.Nullable; - ExternalDocs = schema.ExternalDocs; + ExternalDocs = new(schema.ExternalDocs); Deprecated = schema.Deprecated; - Xml = schema.Xml; + Xml = new(schema.Xml); UnresolvedReference = schema.UnresolvedReference; - Reference = schema.Reference; + Reference = new(schema.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index eaba8b40d..b3b5dbe34 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -90,11 +90,11 @@ public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) In = securityScheme.In; Scheme = securityScheme.Scheme; BearerFormat = securityScheme.BearerFormat; - Flows = securityScheme.Flows; + Flows = new(securityScheme.Flows); OpenIdConnectUrl = securityScheme.OpenIdConnectUrl; - Extensions = securityScheme.Extensions; + Extensions = new Dictionary(securityScheme.Extensions); UnresolvedReference = securityScheme.UnresolvedReference; - Reference = securityScheme.Reference; + Reference = new(securityScheme.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 0ae3f83e9..875bef5c7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -48,8 +48,8 @@ public OpenApiServer(OpenApiServer server) { Description = server.Description; Url = server.Url; - Variables = server.Variables; - Extensions = server.Extensions; + Variables = new Dictionary(server.Variables); + Extensions = new Dictionary(server.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 8813ab69b..b1f222e83 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -46,8 +46,8 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) { Description = serverVariable.Description; Default = serverVariable.Default; - Enum = serverVariable.Enum; - Extensions = serverVariable.Extensions; + Enum = new List(serverVariable.Enum); + Extensions = new Dictionary(serverVariable.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index ed6f916b5..5ecfa0363 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -55,10 +55,10 @@ public OpenApiTag(OpenApiTag tag) { Name = tag.Name; Description = tag.Description; - ExternalDocs = tag.ExternalDocs; - Extensions = tag.Extensions; + ExternalDocs = new(tag.ExternalDocs); + Extensions = new Dictionary(tag.Extensions); UnresolvedReference = tag.UnresolvedReference; - Reference = tag.Reference; + Reference = new(tag.Reference); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index 70e438b1c..eb48132ad 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -61,7 +61,7 @@ public OpenApiXml(OpenApiXml xml) Prefix = xml.Prefix; Attribute = xml.Attribute; Wrapped = xml.Wrapped; - Extensions = xml.Extensions; + Extensions = new Dictionary(xml.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index 12a525b4f..dec51998f 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -16,6 +16,14 @@ public class RuntimeExpressionAnyWrapper : IOpenApiElement private IOpenApiAny _any; private RuntimeExpression _expression; + public RuntimeExpressionAnyWrapper() {} + + public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) + { + Any = runtimeExpressionAnyWrapper.Any; + Expression = runtimeExpressionAnyWrapper.Expression; + } + /// /// Gets/Sets the /// diff --git a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs index 4e6a619a6..05ce022e5 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs @@ -63,6 +63,8 @@ public OpenApiWorkspace() BaseUrl = new Uri("file://" + Environment.CurrentDirectory + "\\" ); } + public OpenApiWorkspace(OpenApiWorkspace workspace){} + /// /// Verify if workspace contains a document based on its URL. /// From d0dc9b34ef8417d091b725006d5f4db1dfdc1208 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 4 Jul 2022 19:47:20 +0300 Subject: [PATCH 04/13] Update public API interface --- test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index f753292e1..8c5c5ff47 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -747,6 +747,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiPaths : Microsoft.OpenApi.Models.OpenApiExtensibleDictionary { public OpenApiPaths() { } + public OpenApiPaths(Microsoft.OpenApi.Models.OpenApiPaths paths) { } } public class OpenApiReference : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { @@ -799,6 +800,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiResponses : Microsoft.OpenApi.Models.OpenApiExtensibleDictionary { public OpenApiResponses() { } + public OpenApiResponses(Microsoft.OpenApi.Models.OpenApiResponses openApiResponses) { } } public class OpenApiSchema : Microsoft.OpenApi.Interfaces.IEffective, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { @@ -969,6 +971,7 @@ namespace Microsoft.OpenApi.Models public class RuntimeExpressionAnyWrapper : Microsoft.OpenApi.Interfaces.IOpenApiElement { public RuntimeExpressionAnyWrapper() { } + public RuntimeExpressionAnyWrapper(Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { } public Microsoft.OpenApi.Any.IOpenApiAny Any { get; set; } public Microsoft.OpenApi.Expressions.RuntimeExpression Expression { get; set; } public void WriteValue(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1082,6 +1085,7 @@ namespace Microsoft.OpenApi.Services public class OpenApiWorkspace { public OpenApiWorkspace() { } + public OpenApiWorkspace(Microsoft.OpenApi.Services.OpenApiWorkspace workspace) { } public OpenApiWorkspace(System.Uri baseUrl) { } public System.Collections.Generic.IEnumerable Artifacts { get; } public System.Uri BaseUrl { get; } From dc300ab567f94c0c92142d18266d2e380db2e085 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 4 Jul 2022 20:00:04 +0300 Subject: [PATCH 05/13] Add XML comments --- src/Microsoft.OpenApi/Models/OpenApiPaths.cs | 7 +++++++ src/Microsoft.OpenApi/Models/OpenApiResponses.cs | 6 ++++++ .../Models/RuntimeExpressionAnyWrapper.cs | 6 ++++++ src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs | 3 +++ 4 files changed, 22 insertions(+) diff --git a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs index 2ba371e61..f65ccb9c4 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -8,7 +8,14 @@ namespace Microsoft.OpenApi.Models /// public class OpenApiPaths : OpenApiExtensibleDictionary { + /// + /// Parameterless constructor + /// public OpenApiPaths() {} + + /// + /// Initializes a copy of object + /// public OpenApiPaths(OpenApiPaths paths) {} } diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs index 28fe62ad4..24f4eba0d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs @@ -8,8 +8,14 @@ namespace Microsoft.OpenApi.Models /// public class OpenApiResponses : OpenApiExtensibleDictionary { + /// + /// Parameterless constructor + /// public OpenApiResponses() { } + /// + /// Initializes a copy of object + /// public OpenApiResponses(OpenApiResponses openApiResponses) { } } diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index dec51998f..3acb2ed82 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -16,8 +16,14 @@ public class RuntimeExpressionAnyWrapper : IOpenApiElement private IOpenApiAny _any; private RuntimeExpression _expression; + /// + /// Parameterless constructor + /// public RuntimeExpressionAnyWrapper() {} + /// + /// Initializes a copy of an object + /// public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { Any = runtimeExpressionAnyWrapper.Any; diff --git a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs index 05ce022e5..7827a50c1 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs @@ -63,6 +63,9 @@ public OpenApiWorkspace() BaseUrl = new Uri("file://" + Environment.CurrentDirectory + "\\" ); } + /// + /// Initializes a copy of an object + /// public OpenApiWorkspace(OpenApiWorkspace workspace){} /// From 17d437104ed27adce74cfe27500e8204ecda16e7 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 11:59:05 +0300 Subject: [PATCH 06/13] Implement ICloneable for type IOpenApiAny --- src/Microsoft.OpenApi/Any/IOpenApiAny.cs | 3 +- src/Microsoft.OpenApi/Any/OpenApiArray.cs | 12 ++++- src/Microsoft.OpenApi/Any/OpenApiNull.cs | 10 +++++ src/Microsoft.OpenApi/Any/OpenApiObject.cs | 9 ++++ src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs | 45 +++++++++++++++++++ .../Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 2 +- .../Models/OpenApiMediaType.cs | 2 +- .../Models/OpenApiParameter.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 4 +- .../Models/RuntimeExpressionAnyWrapper.cs | 2 +- 11 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs index 26c5f4d87..13fd70269 100644 --- a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs +++ b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Any @@ -8,7 +9,7 @@ namespace Microsoft.OpenApi.Any /// /// Base interface for all the types that represent Open API Any. /// - public interface IOpenApiAny : IOpenApiElement, IOpenApiExtension + public interface IOpenApiAny : IOpenApiElement, IOpenApiExtension, ICloneable { /// /// Type of an . diff --git a/src/Microsoft.OpenApi/Any/OpenApiArray.cs b/src/Microsoft.OpenApi/Any/OpenApiArray.cs index 5ef0087f2..343b44a16 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiArray.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiArray.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using Microsoft.OpenApi.Writers; +using System; using System.Collections.Generic; namespace Microsoft.OpenApi.Any @@ -9,13 +10,22 @@ namespace Microsoft.OpenApi.Any /// /// Open API array. /// - public class OpenApiArray : List, IOpenApiAny + public class OpenApiArray : List, IOpenApiAny, ICloneable { /// /// The type of /// public AnyType AnyType { get; } = AnyType.Array; + /// + /// Implement ICloneable interface to allow for deep copying + /// + /// A new copy of + public object Clone() + { + return new OpenApiArray(); + } + /// /// Write out contents of OpenApiArray to passed writer /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiNull.cs b/src/Microsoft.OpenApi/Any/OpenApiNull.cs index 229409d95..426fbd031 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiNull.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiNull.cs @@ -15,6 +15,16 @@ public class OpenApiNull : IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Null; + + /// + /// Implement ICloneable interface to allow for deep copying + /// + /// A new copy of + public object Clone() + { + return new OpenApiNull(); + } + /// /// Write out null representation /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiObject.cs b/src/Microsoft.OpenApi/Any/OpenApiObject.cs index cd2f6ee64..9b8bdaf78 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiObject.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiObject.cs @@ -16,6 +16,15 @@ public class OpenApiObject : Dictionary, IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Object; + /// + /// Implement ICloneable interface to allow for deep copying + /// + /// A new copy of + public object Clone() + { + return new OpenApiObject(); + } + /// /// Serialize OpenApiObject to writer /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs index b6a111e35..119d7dc00 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Reflection; using System.Text; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Properties; @@ -24,11 +25,21 @@ public OpenApiPrimitive(T value) Value = value; } + /// + /// + /// + /// + public OpenApiPrimitive(OpenApiPrimitive openApiPrimitive) + { + Value = openApiPrimitive.Value; + } + /// /// The kind of . /// public AnyType AnyType { get; } = AnyType.Primitive; + /// /// The primitive class this object represents. /// @@ -39,6 +50,40 @@ public OpenApiPrimitive(T value) /// public T Value { get; } + /// + /// Implement ICloneable interface to allow for deep copying + /// + /// A new copy of + public object Clone() + { + var clone = CloneFromCopyConstructor(this); + if (clone == null) throw new ApplicationException("There's no copy constructor defined"); + return clone; + } + + /// + /// Clones an instance of object from the copy constructor + /// + /// The object instance. + /// A clone copy. + public static object CloneFromCopyConstructor(Object obj) + { + if (obj != null) + { + Type t = obj.GetType(); + foreach (ConstructorInfo ci in t.GetConstructors()) + { + ParameterInfo[] pi = ci.GetParameters(); + if (pi.Length == 1 && pi[0].ParameterType == t) + { + return ci.Invoke(new object[] { obj }); + } + } + } + + return null; + } + /// /// Write out content of primitive element /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index b9d5b54bc..6d16ccf27 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -66,7 +66,7 @@ public OpenApiExample(OpenApiExample example) { Summary = example.Summary; Description = example.Description; - Value = example.Value; + Value = (IOpenApiAny)example.Value.Clone(); ExternalValue = example.ExternalValue; Extensions = new Dictionary(example.Extensions); Reference = new(example.Reference); diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 85a27794f..330662c48 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -106,7 +106,7 @@ public OpenApiHeader(OpenApiHeader header) Explode = header.Explode; AllowReserved = header.AllowReserved; Schema = new(header.Schema); - Example = header.Example; + Example = (IOpenApiAny)header.Example.Clone(); Examples = new Dictionary(header.Examples); Content = new Dictionary(header.Content); Extensions = new Dictionary(header.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 102c9bbbf..178e97c62 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -54,7 +54,7 @@ public OpenApiMediaType() {} public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = new(mediaType.Schema); - Example = mediaType.Example; + Example = (IOpenApiAny)mediaType.Example.Clone(); Examples = new Dictionary(mediaType.Examples); Encoding = new Dictionary(mediaType.Encoding); Extensions = new Dictionary(mediaType.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 94eca4a75..36cdfe595 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -157,7 +157,7 @@ public OpenApiParameter(OpenApiParameter parameter) AllowReserved = parameter.AllowReserved; Schema = new(parameter.Schema); Examples = new Dictionary(parameter.Examples); - Example = parameter.Example; + Example = (IOpenApiAny)parameter.Example.Clone(); Content = new Dictionary(parameter.Content); Extensions = new Dictionary(parameter.Extensions); AllowEmptyValue = parameter.AllowEmptyValue; diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index a60cfae77..b10b7e768 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -264,7 +264,7 @@ public OpenApiSchema(OpenApiSchema schema) MinLength = schema.MinLength; Pattern = schema.Pattern; MultipleOf = schema.MultipleOf; - Default = schema.Default; + Default = (IOpenApiAny)schema.Default.Clone(); ReadOnly = schema.ReadOnly; WriteOnly = schema.WriteOnly; AllOf = new List(schema.AllOf); @@ -282,7 +282,7 @@ public OpenApiSchema(OpenApiSchema schema) AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; AdditionalProperties = new(schema.AdditionalProperties); Discriminator = new(schema.Discriminator); - Example = schema.Example; + Example = (IOpenApiAny)schema.Example.Clone(); Enum = new List(schema.Enum); Nullable = schema.Nullable; ExternalDocs = new(schema.ExternalDocs); diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index 3acb2ed82..be450cee2 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -26,7 +26,7 @@ public RuntimeExpressionAnyWrapper() {} /// public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { - Any = runtimeExpressionAnyWrapper.Any; + Any = (IOpenApiAny)runtimeExpressionAnyWrapper.Any.Clone(); Expression = runtimeExpressionAnyWrapper.Expression; } From 233da50838de49415a3662ff96166657c6cf59e4 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 12:00:49 +0300 Subject: [PATCH 07/13] Initialize a new Uri instance during copying --- src/Microsoft.OpenApi/Models/OpenApiContact.cs | 2 +- .../Models/OpenApiExternalDocs.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiLicense.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs | 6 +++--- .../Models/OpenApiSecurityScheme.cs | 2 +- .../Models/OpenApiLicenseTests.cs | 15 +++++++++++++++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index a49c80a08..9447d424e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -46,7 +46,7 @@ public OpenApiContact() { } public OpenApiContact(OpenApiContact contact) { Name = contact.Name; - Url = contact.Url; + Url = new Uri(contact.Url.OriginalString); Email = contact.Email; Extensions = new Dictionary(contact.Extensions); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index afc9a5b3c..95af8f01b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -40,7 +40,7 @@ public OpenApiExternalDocs() {} public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { Description = externalDocs.Description; - Url = externalDocs.Url; + Url = new Uri(externalDocs.Url.OriginalString); Extensions = new Dictionary(externalDocs.Extensions); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 452f98918..431789aac 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -40,7 +40,7 @@ public OpenApiLicense() {} public OpenApiLicense(OpenApiLicense license) { Name = license.Name; - Url = license.Url; + Url = new Uri(license.Url.OriginalString); Extensions = new Dictionary(license.Extensions); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 1ee47a499..02856d4cd 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -51,9 +51,9 @@ public OpenApiOAuthFlow() {} /// public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) { - AuthorizationUrl = oAuthFlow.AuthorizationUrl; - TokenUrl = oAuthFlow.TokenUrl; - RefreshUrl = oAuthFlow.RefreshUrl; + 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); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index b3b5dbe34..b87adf573 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -91,7 +91,7 @@ public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) Scheme = securityScheme.Scheme; BearerFormat = securityScheme.BearerFormat; Flows = new(securityScheme.Flows); - OpenIdConnectUrl = securityScheme.OpenIdConnectUrl; + OpenIdConnectUrl = new Uri(securityScheme.OpenIdConnectUrl.OriginalString); Extensions = new Dictionary(securityScheme.Extensions); UnresolvedReference = securityScheme.UnresolvedReference; Reference = new(securityScheme.Reference); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs index 52e99b0b4..46717ecec 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs @@ -108,5 +108,20 @@ public void SerializeAdvanceLicenseAsYamlWorks(OpenApiSpecVersion version) expected = expected.MakeLineBreaksEnvironmentNeutral(); actual.Should().Be(expected); } + + [Fact] + public void ShouldCopyFromOriginalObjectWithoutMutating() + { + // Arrange + var licenseCopy = new OpenApiLicense(AdvanceLicense); + + // Act + licenseCopy.Name = ""; + licenseCopy.Url = new Uri("https://exampleCopy.com"); + + // Assert + Assert.NotEqual(AdvanceLicense.Name, licenseCopy.Name); + Assert.NotEqual(AdvanceLicense.Url, licenseCopy.Url); + } } } From 1dbab5dc1f1cd03fc164f4e1db4cfd5dfde6cfb9 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 12:12:35 +0300 Subject: [PATCH 08/13] Update documentation --- src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs index 119d7dc00..0c81c6972 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs @@ -26,7 +26,7 @@ public OpenApiPrimitive(T value) } /// - /// + /// Initializes a copy of an object /// /// public OpenApiPrimitive(OpenApiPrimitive openApiPrimitive) From 12fa16b758366c9063b0434da33ee16830033a17 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 12:33:23 +0300 Subject: [PATCH 09/13] Update public API interface --- .../PublicApi/PublicApi.approved.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 8c5c5ff47..ed9fb0962 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -11,18 +11,19 @@ namespace Microsoft.OpenApi.Any Array = 2, Object = 3, } - public interface IOpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public interface IOpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { Microsoft.OpenApi.Any.AnyType AnyType { get; } } - public interface IOpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public interface IOpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public class OpenApiArray : System.Collections.Generic.List, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public class OpenApiArray : System.Collections.Generic.List, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { public OpenApiArray() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } + public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public class OpenApiBinary : Microsoft.OpenApi.Any.OpenApiPrimitive @@ -71,16 +72,18 @@ namespace Microsoft.OpenApi.Any public OpenApiLong(long value) { } public override Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public class OpenApiNull : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public class OpenApiNull : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { public OpenApiNull() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } + public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } - public class OpenApiObject : System.Collections.Generic.Dictionary, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public class OpenApiObject : System.Collections.Generic.Dictionary, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { public OpenApiObject() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } + public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public class OpenApiPassword : Microsoft.OpenApi.Any.OpenApiPrimitive @@ -88,13 +91,16 @@ namespace Microsoft.OpenApi.Any public OpenApiPassword(string value) { } public override Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public abstract class OpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Any.IOpenApiPrimitive, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension + public abstract class OpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Any.IOpenApiPrimitive, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable { + public OpenApiPrimitive(Microsoft.OpenApi.Any.OpenApiPrimitive openApiPrimitive) { } public OpenApiPrimitive(T value) { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } public abstract Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } public T Value { get; } + public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } + public static object CloneFromCopyConstructor(object obj) { } } public class OpenApiString : Microsoft.OpenApi.Any.OpenApiPrimitive { From 7cd6abc1d5fd9dc0a132397284cb4a9847462756 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 19:42:19 +0300 Subject: [PATCH 10/13] Revert ICloneable changes and use reflection for deep copying --- src/Microsoft.OpenApi/Any/CloneHelper.cs | 36 +++++++++++++++++++ src/Microsoft.OpenApi/Any/IOpenApiAny.cs | 2 +- src/Microsoft.OpenApi/Any/OpenApiArray.cs | 11 +----- src/Microsoft.OpenApi/Any/OpenApiNull.cs | 10 ------ src/Microsoft.OpenApi/Any/OpenApiObject.cs | 9 ----- src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs | 35 ------------------ .../Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 2 +- .../Models/OpenApiMediaType.cs | 2 +- .../Models/OpenApiParameter.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 4 +-- .../Models/RuntimeExpressionAnyWrapper.cs | 2 +- .../PublicApi/PublicApi.approved.txt | 22 ++++++------ 13 files changed, 56 insertions(+), 83 deletions(-) create mode 100644 src/Microsoft.OpenApi/Any/CloneHelper.cs diff --git a/src/Microsoft.OpenApi/Any/CloneHelper.cs b/src/Microsoft.OpenApi/Any/CloneHelper.cs new file mode 100644 index 000000000..43bec778e --- /dev/null +++ b/src/Microsoft.OpenApi/Any/CloneHelper.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +using System.Reflection; + +namespace Microsoft.OpenApi.Any +{ + /// + /// Contains logic for cloning objects through copy constructors. + /// + public class CloneHelper + { + /// + /// Clones an instance of object from the copy constructor + /// + /// The object instance. + /// A clone copy or the object itself. + public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj) + { + if (obj != null) + { + var t = obj.GetType(); + foreach (ConstructorInfo ci in t.GetConstructors()) + { + ParameterInfo[] pi = ci.GetParameters(); + if (pi.Length == 1 && pi[0].ParameterType == t) + { + return (IOpenApiAny)ci.Invoke(new object[] { obj }); + } + } + } + + return obj; + } + } +} diff --git a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs index 13fd70269..5d1cf63e4 100644 --- a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs +++ b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs @@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.Any /// /// Base interface for all the types that represent Open API Any. /// - public interface IOpenApiAny : IOpenApiElement, IOpenApiExtension, ICloneable + public interface IOpenApiAny : IOpenApiElement, IOpenApiExtension { /// /// Type of an . diff --git a/src/Microsoft.OpenApi/Any/OpenApiArray.cs b/src/Microsoft.OpenApi/Any/OpenApiArray.cs index 343b44a16..d19337f44 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiArray.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiArray.cs @@ -10,22 +10,13 @@ namespace Microsoft.OpenApi.Any /// /// Open API array. /// - public class OpenApiArray : List, IOpenApiAny, ICloneable + public class OpenApiArray : List, IOpenApiAny { /// /// The type of /// public AnyType AnyType { get; } = AnyType.Array; - /// - /// Implement ICloneable interface to allow for deep copying - /// - /// A new copy of - public object Clone() - { - return new OpenApiArray(); - } - /// /// Write out contents of OpenApiArray to passed writer /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiNull.cs b/src/Microsoft.OpenApi/Any/OpenApiNull.cs index 426fbd031..229409d95 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiNull.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiNull.cs @@ -15,16 +15,6 @@ public class OpenApiNull : IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Null; - - /// - /// Implement ICloneable interface to allow for deep copying - /// - /// A new copy of - public object Clone() - { - return new OpenApiNull(); - } - /// /// Write out null representation /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiObject.cs b/src/Microsoft.OpenApi/Any/OpenApiObject.cs index 9b8bdaf78..cd2f6ee64 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiObject.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiObject.cs @@ -16,15 +16,6 @@ public class OpenApiObject : Dictionary, IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Object; - /// - /// Implement ICloneable interface to allow for deep copying - /// - /// A new copy of - public object Clone() - { - return new OpenApiObject(); - } - /// /// Serialize OpenApiObject to writer /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs index 0c81c6972..5e32f1b2d 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs @@ -39,7 +39,6 @@ public OpenApiPrimitive(OpenApiPrimitive openApiPrimitive) /// public AnyType AnyType { get; } = AnyType.Primitive; - /// /// The primitive class this object represents. /// @@ -50,40 +49,6 @@ public OpenApiPrimitive(OpenApiPrimitive openApiPrimitive) /// public T Value { get; } - /// - /// Implement ICloneable interface to allow for deep copying - /// - /// A new copy of - public object Clone() - { - var clone = CloneFromCopyConstructor(this); - if (clone == null) throw new ApplicationException("There's no copy constructor defined"); - return clone; - } - - /// - /// Clones an instance of object from the copy constructor - /// - /// The object instance. - /// A clone copy. - public static object CloneFromCopyConstructor(Object obj) - { - if (obj != null) - { - Type t = obj.GetType(); - foreach (ConstructorInfo ci in t.GetConstructors()) - { - ParameterInfo[] pi = ci.GetParameters(); - if (pi.Length == 1 && pi[0].ParameterType == t) - { - return ci.Invoke(new object[] { obj }); - } - } - } - - return null; - } - /// /// Write out content of primitive element /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 6d16ccf27..8f7da5399 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -66,7 +66,7 @@ public OpenApiExample(OpenApiExample example) { Summary = example.Summary; Description = example.Description; - Value = (IOpenApiAny)example.Value.Clone(); + Value = CloneHelper.CloneFromCopyConstructor(example.Value); ExternalValue = example.ExternalValue; Extensions = new Dictionary(example.Extensions); Reference = new(example.Reference); diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 330662c48..5ac25566b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -106,7 +106,7 @@ public OpenApiHeader(OpenApiHeader header) Explode = header.Explode; AllowReserved = header.AllowReserved; Schema = new(header.Schema); - Example = (IOpenApiAny)header.Example.Clone(); + Example = CloneHelper.CloneFromCopyConstructor(header.Example); Examples = new Dictionary(header.Examples); Content = new Dictionary(header.Content); Extensions = new Dictionary(header.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 178e97c62..4a9b857d0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -54,7 +54,7 @@ public OpenApiMediaType() {} public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = new(mediaType.Schema); - Example = (IOpenApiAny)mediaType.Example.Clone(); + Example = CloneHelper.CloneFromCopyConstructor(mediaType.Example); Examples = new Dictionary(mediaType.Examples); Encoding = new Dictionary(mediaType.Encoding); Extensions = new Dictionary(mediaType.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 36cdfe595..03dfd1a42 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -157,7 +157,7 @@ public OpenApiParameter(OpenApiParameter parameter) AllowReserved = parameter.AllowReserved; Schema = new(parameter.Schema); Examples = new Dictionary(parameter.Examples); - Example = (IOpenApiAny)parameter.Example.Clone(); + Example = CloneHelper.CloneFromCopyConstructor(parameter.Example); Content = new Dictionary(parameter.Content); Extensions = new Dictionary(parameter.Extensions); AllowEmptyValue = parameter.AllowEmptyValue; diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index b10b7e768..36ef62dd1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -264,7 +264,7 @@ public OpenApiSchema(OpenApiSchema schema) MinLength = schema.MinLength; Pattern = schema.Pattern; MultipleOf = schema.MultipleOf; - Default = (IOpenApiAny)schema.Default.Clone(); + Default = CloneHelper.CloneFromCopyConstructor(schema.Default); ReadOnly = schema.ReadOnly; WriteOnly = schema.WriteOnly; AllOf = new List(schema.AllOf); @@ -282,7 +282,7 @@ public OpenApiSchema(OpenApiSchema schema) AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; AdditionalProperties = new(schema.AdditionalProperties); Discriminator = new(schema.Discriminator); - Example = (IOpenApiAny)schema.Example.Clone(); + Example = CloneHelper.CloneFromCopyConstructor(schema.Example); Enum = new List(schema.Enum); Nullable = schema.Nullable; ExternalDocs = new(schema.ExternalDocs); diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index be450cee2..37764acb1 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -26,7 +26,7 @@ public RuntimeExpressionAnyWrapper() {} /// public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { - Any = (IOpenApiAny)runtimeExpressionAnyWrapper.Any.Clone(); + Any = CloneHelper.CloneFromCopyConstructor(runtimeExpressionAnyWrapper.Any); Expression = runtimeExpressionAnyWrapper.Expression; } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index ed9fb0962..cdeeaad81 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -11,19 +11,23 @@ namespace Microsoft.OpenApi.Any Array = 2, Object = 3, } - public interface IOpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public class CloneHelper + { + public CloneHelper() { } + public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor(Microsoft.OpenApi.Any.IOpenApiAny obj) { } + } + public interface IOpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { Microsoft.OpenApi.Any.AnyType AnyType { get; } } - public interface IOpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public interface IOpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public class OpenApiArray : System.Collections.Generic.List, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public class OpenApiArray : System.Collections.Generic.List, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiArray() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } - public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public class OpenApiBinary : Microsoft.OpenApi.Any.OpenApiPrimitive @@ -72,18 +76,16 @@ namespace Microsoft.OpenApi.Any public OpenApiLong(long value) { } public override Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public class OpenApiNull : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public class OpenApiNull : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiNull() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } - public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } - public class OpenApiObject : System.Collections.Generic.Dictionary, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public class OpenApiObject : System.Collections.Generic.Dictionary, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiObject() { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } - public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public class OpenApiPassword : Microsoft.OpenApi.Any.OpenApiPrimitive @@ -91,16 +93,14 @@ namespace Microsoft.OpenApi.Any public OpenApiPassword(string value) { } public override Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } - public abstract class OpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Any.IOpenApiPrimitive, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension, System.ICloneable + public abstract class OpenApiPrimitive : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Any.IOpenApiPrimitive, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiPrimitive(Microsoft.OpenApi.Any.OpenApiPrimitive openApiPrimitive) { } public OpenApiPrimitive(T value) { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } public abstract Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } public T Value { get; } - public object Clone() { } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } - public static object CloneFromCopyConstructor(object obj) { } } public class OpenApiString : Microsoft.OpenApi.Any.OpenApiPrimitive { From 85a0a1f1f20abb58043269b8b6599109155983cf Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 20:19:02 +0300 Subject: [PATCH 11/13] Clean up and add copy constructors --- src/Microsoft.OpenApi/Any/IOpenApiAny.cs | 1 - .../{CloneHelper.cs => OpenApiAnyCloneHelper.cs} | 2 +- src/Microsoft.OpenApi/Any/OpenApiArray.cs | 13 +++++++++++++ src/Microsoft.OpenApi/Any/OpenApiNull.cs | 13 +++++++++++++ src/Microsoft.OpenApi/Any/OpenApiObject.cs | 13 +++++++++++++ src/Microsoft.OpenApi/Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiMediaType.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 4 ++-- .../Models/RuntimeExpressionAnyWrapper.cs | 2 +- 11 files changed, 47 insertions(+), 9 deletions(-) rename src/Microsoft.OpenApi/Any/{CloneHelper.cs => OpenApiAnyCloneHelper.cs} (96%) diff --git a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs index 5d1cf63e4..26c5f4d87 100644 --- a/src/Microsoft.OpenApi/Any/IOpenApiAny.cs +++ b/src/Microsoft.OpenApi/Any/IOpenApiAny.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Any diff --git a/src/Microsoft.OpenApi/Any/CloneHelper.cs b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs similarity index 96% rename from src/Microsoft.OpenApi/Any/CloneHelper.cs rename to src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs index 43bec778e..4a67e074e 100644 --- a/src/Microsoft.OpenApi/Any/CloneHelper.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs @@ -8,7 +8,7 @@ namespace Microsoft.OpenApi.Any /// /// Contains logic for cloning objects through copy constructors. /// - public class CloneHelper + public class OpenApiAnyCloneHelper { /// /// Clones an instance of object from the copy constructor diff --git a/src/Microsoft.OpenApi/Any/OpenApiArray.cs b/src/Microsoft.OpenApi/Any/OpenApiArray.cs index d19337f44..2c877d631 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiArray.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiArray.cs @@ -17,6 +17,19 @@ public class OpenApiArray : List, IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Array; + /// + /// Parameterless constructor + /// + public OpenApiArray() { } + + /// + /// Initializes a copy of object + /// + public OpenApiArray(OpenApiArray array) + { + AnyType = array.AnyType; + } + /// /// Write out contents of OpenApiArray to passed writer /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiNull.cs b/src/Microsoft.OpenApi/Any/OpenApiNull.cs index 229409d95..f1772c3e4 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiNull.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiNull.cs @@ -15,6 +15,19 @@ public class OpenApiNull : IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Null; + /// + /// Parameterless constructor + /// + public OpenApiNull() { } + + /// + /// Initializes a copy of object + /// + public OpenApiNull(OpenApiNull openApiNull) + { + AnyType = openApiNull.AnyType; + } + /// /// Write out null representation /// diff --git a/src/Microsoft.OpenApi/Any/OpenApiObject.cs b/src/Microsoft.OpenApi/Any/OpenApiObject.cs index cd2f6ee64..d7e56e341 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiObject.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiObject.cs @@ -16,6 +16,19 @@ public class OpenApiObject : Dictionary, IOpenApiAny /// public AnyType AnyType { get; } = AnyType.Object; + /// + /// Parameterless constructor + /// + public OpenApiObject() { } + + /// + /// Initializes a copy of object + /// + public OpenApiObject(OpenApiObject obj) + { + AnyType = obj.AnyType; + } + /// /// Serialize OpenApiObject to writer /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 8f7da5399..5e105be26 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -66,7 +66,7 @@ public OpenApiExample(OpenApiExample example) { Summary = example.Summary; Description = example.Description; - Value = CloneHelper.CloneFromCopyConstructor(example.Value); + Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example.Value); ExternalValue = example.ExternalValue; Extensions = new Dictionary(example.Extensions); Reference = new(example.Reference); diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 5ac25566b..b91440df8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -106,7 +106,7 @@ public OpenApiHeader(OpenApiHeader header) Explode = header.Explode; AllowReserved = header.AllowReserved; Schema = new(header.Schema); - Example = CloneHelper.CloneFromCopyConstructor(header.Example); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header.Example); Examples = new Dictionary(header.Examples); Content = new Dictionary(header.Content); Extensions = new Dictionary(header.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 4a9b857d0..94dcbdfa7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -54,7 +54,7 @@ public OpenApiMediaType() {} public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = new(mediaType.Schema); - Example = CloneHelper.CloneFromCopyConstructor(mediaType.Example); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType.Example); Examples = new Dictionary(mediaType.Examples); Encoding = new Dictionary(mediaType.Encoding); Extensions = new Dictionary(mediaType.Extensions); diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 03dfd1a42..f0b21b0d9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -157,7 +157,7 @@ public OpenApiParameter(OpenApiParameter parameter) AllowReserved = parameter.AllowReserved; Schema = new(parameter.Schema); Examples = new Dictionary(parameter.Examples); - Example = CloneHelper.CloneFromCopyConstructor(parameter.Example); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter.Example); Content = new Dictionary(parameter.Content); Extensions = new Dictionary(parameter.Extensions); AllowEmptyValue = parameter.AllowEmptyValue; diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 36ef62dd1..d43756887 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -264,7 +264,7 @@ public OpenApiSchema(OpenApiSchema schema) MinLength = schema.MinLength; Pattern = schema.Pattern; MultipleOf = schema.MultipleOf; - Default = CloneHelper.CloneFromCopyConstructor(schema.Default); + Default = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema.Default); ReadOnly = schema.ReadOnly; WriteOnly = schema.WriteOnly; AllOf = new List(schema.AllOf); @@ -282,7 +282,7 @@ public OpenApiSchema(OpenApiSchema schema) AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; AdditionalProperties = new(schema.AdditionalProperties); Discriminator = new(schema.Discriminator); - Example = CloneHelper.CloneFromCopyConstructor(schema.Example); + Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema.Example); Enum = new List(schema.Enum); Nullable = schema.Nullable; ExternalDocs = new(schema.ExternalDocs); diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index 37764acb1..85c64dd30 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -26,7 +26,7 @@ public RuntimeExpressionAnyWrapper() {} /// public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { - Any = CloneHelper.CloneFromCopyConstructor(runtimeExpressionAnyWrapper.Any); + Any = OpenApiAnyCloneHelper.CloneFromCopyConstructor(runtimeExpressionAnyWrapper.Any); Expression = runtimeExpressionAnyWrapper.Expression; } From e034d0ca08dfe3be0c71c0a3d806961bf56ef0fa Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 20:22:09 +0300 Subject: [PATCH 12/13] Revert public API changes --- .../PublicApi/PublicApi.approved.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index cdeeaad81..e9d78acb2 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -11,11 +11,6 @@ namespace Microsoft.OpenApi.Any Array = 2, Object = 3, } - public class CloneHelper - { - public CloneHelper() { } - public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor(Microsoft.OpenApi.Any.IOpenApiAny obj) { } - } public interface IOpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { Microsoft.OpenApi.Any.AnyType AnyType { get; } @@ -24,9 +19,15 @@ namespace Microsoft.OpenApi.Any { Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; } } + public class OpenApiAnyCloneHelper + { + public OpenApiAnyCloneHelper() { } + public static Microsoft.OpenApi.Any.IOpenApiAny CloneFromCopyConstructor(Microsoft.OpenApi.Any.IOpenApiAny obj) { } + } public class OpenApiArray : System.Collections.Generic.List, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiArray() { } + public OpenApiArray(Microsoft.OpenApi.Any.OpenApiArray array) { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } @@ -79,12 +80,14 @@ namespace Microsoft.OpenApi.Any public class OpenApiNull : Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiNull() { } + public OpenApiNull(Microsoft.OpenApi.Any.OpenApiNull openApiNull) { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public class OpenApiObject : System.Collections.Generic.Dictionary, Microsoft.OpenApi.Any.IOpenApiAny, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { public OpenApiObject() { } + public OpenApiObject(Microsoft.OpenApi.Any.OpenApiObject obj) { } public Microsoft.OpenApi.Any.AnyType AnyType { get; } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } From 87180dd37e1160dd824beebf61188670d0a180ff Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 6 Jul 2022 20:30:51 +0300 Subject: [PATCH 13/13] Remove unnecessary using --- src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs index 5e32f1b2d..e0abda167 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. using System; -using System.Reflection; using System.Text; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Properties;