From e3312eabf418caeff9a143ab95911b75efe6c9fb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:57:27 +0000 Subject: [PATCH 1/7] Bump Microsoft.OpenApi.OData from 1.4.0-preview1 to 1.4.0-preview2 Bumps [Microsoft.OpenApi.OData](https://github.com/Microsoft/OpenAPI.NET.OData) from 1.4.0-preview1 to 1.4.0-preview2. - [Release notes](https://github.com/Microsoft/OpenAPI.NET.OData/releases) - [Commits](https://github.com/Microsoft/OpenAPI.NET.OData/commits) --- updated-dependencies: - dependency-name: Microsoft.OpenApi.OData dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 092c782a7..aad865a3a 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -1,4 +1,4 @@ - + Exe @@ -43,7 +43,7 @@ - + From 4e406ceaa6755d640bbebae934ef485455c9ea8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:57:34 +0000 Subject: [PATCH 2/7] Bump Verify.Xunit from 19.12.1 to 19.12.2 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 19.12.1 to 19.12.2. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/19.12.1...19.12.2) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 89c2bacf2..5a177d8f0 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -28,7 +28,7 @@ - + all From d940bf627bf368733b558dab088f32e3c7c82306 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 17 Apr 2023 11:34:23 +0300 Subject: [PATCH 3/7] Revert dictionary clone helper logic in the copy constructors to unblock kiota --- .../Any/OpenApiAnyCloneHelper.cs | 5 ++- .../Helpers/DictionaryCloneHelper.cs | 12 +++--- .../Microsoft.OpenApi.csproj | 3 ++ .../Models/OpenApiComponents.cs | 18 ++++----- .../Models/OpenApiEncoding.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 4 +- .../Models/OpenApiMediaType.cs | 4 +- .../Models/OpenApiOperation.cs | 2 +- .../Models/OpenApiParameter.cs | 4 +- .../Models/OpenApiPathItem.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiPaths.cs | 2 +- .../Models/OpenApiRequestBody.cs | 2 +- .../Models/OpenApiResponse.cs | 6 +-- .../Models/OpenApiResponses.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 2 +- .../Models/OpenApiDocumentTests.cs | 40 +++++++++---------- 17 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs index 4a67e074e..8e75c9d39 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs @@ -2,6 +2,9 @@ // Licensed under the MIT license. using System.Reflection; +using Microsoft.OpenApi.Helpers; +using System.Text.Json.Serialization; +using System.Text.Json; namespace Microsoft.OpenApi.Any { @@ -27,7 +30,7 @@ public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj) { return (IOpenApiAny)ci.Invoke(new object[] { obj }); } - } + } } return obj; diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs index 1af7bc8c4..ef349a477 100644 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -19,12 +19,12 @@ internal static class DictionaryCloneHelper /// The target dictionary to clone. /// The cloned dictionary. internal static Dictionary Clone(IDictionary dictionary) - { + { if (dictionary is null) return null; - + var clonedDictionary = new Dictionary(dictionary.Keys.Count); var clonedObjects = new Dictionary(); - + foreach (var keyValuePair in dictionary) { // If the object has already been cloned, use the cloned object instead of cloning it again @@ -36,11 +36,11 @@ internal static Dictionary Clone(IDictionary dictionary) { // Create instance of the specified type using the constructor matching the specified parameter types. clonedDictionary[keyValuePair.Key] = (U)Activator.CreateInstance(keyValuePair.Value.GetType(), keyValuePair.Value); - + // Add the cloned object to the dictionary of cloned objects clonedObjects.Add(keyValuePair.Value, clonedDictionary[keyValuePair.Key]); - } - } + } + } return clonedDictionary; } diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 4a291f120..ba72031e6 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -33,6 +33,9 @@ true + + + diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 9a397b1b0..b8877eeff 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -77,15 +77,15 @@ public OpenApiComponents() { } /// public OpenApiComponents(OpenApiComponents components) { - Schemas = DictionaryCloneHelper.Clone(components?.Schemas); - Responses = DictionaryCloneHelper.Clone(components?.Responses); - Parameters = DictionaryCloneHelper.Clone(components?.Parameters); - Examples = DictionaryCloneHelper.Clone(components?.Examples); - RequestBodies = DictionaryCloneHelper.Clone(components?.RequestBodies); - Headers = DictionaryCloneHelper.Clone(components?.Headers); - SecuritySchemes = DictionaryCloneHelper.Clone(components?.SecuritySchemes); - Links = DictionaryCloneHelper.Clone(components?.Links); - Callbacks = DictionaryCloneHelper.Clone(components?.Callbacks); + Schemas = components?.Schemas != null ? new Dictionary(components.Schemas) : null; + Responses = components?.Responses != null ? new Dictionary(components.Responses) : null; + Parameters = components?.Parameters != null ? new Dictionary(components.Parameters) : null; + Examples = components?.Examples != null ? new Dictionary(components.Examples) : null; + RequestBodies = components?.RequestBodies != null ? new Dictionary(components.RequestBodies) : null; + Headers = components?.Headers != null ? new Dictionary(components.Headers) : null; + SecuritySchemes = components?.SecuritySchemes != null ? new Dictionary(components.SecuritySchemes) : null; + Links = components?.Links != null ? new Dictionary(components.Links) : null; + Callbacks = components?.Callbacks != null ? new Dictionary(components.Callbacks) : null; Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 94c8e5888..e039a04ee 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -65,7 +65,7 @@ public OpenApiEncoding() {} public OpenApiEncoding(OpenApiEncoding encoding) { ContentType = encoding?.ContentType ?? ContentType; - Headers = DictionaryCloneHelper.Clone(encoding?.Headers); + Headers = encoding?.Headers != null ? new Dictionary(encoding.Headers) : null; Style = encoding?.Style ?? Style; Explode = encoding?.Explode ?? Explode; AllowReserved = encoding?.AllowReserved ?? AllowReserved; diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 91882aade..359c1c70c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -108,8 +108,8 @@ public OpenApiHeader(OpenApiHeader header) AllowReserved = header?.AllowReserved ?? AllowReserved; Schema = header?.Schema != null ? new(header?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example); - Examples = DictionaryCloneHelper.Clone(header?.Examples); - Content = DictionaryCloneHelper.Clone(header?.Content); + Examples = header?.Examples != null ? new Dictionary(header.Examples) : null; + Content = header?.Content != null ? new Dictionary(header.Content) : null; Extensions = header?.Extensions != null ? new Dictionary(header.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index a8a0497f4..276cc3807 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -56,8 +56,8 @@ public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); - Examples = DictionaryCloneHelper.Clone(mediaType?.Examples); - Encoding = DictionaryCloneHelper.Clone(mediaType?.Encoding); + Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples) : null; + Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding) : null; Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 526e4c7ca..a1c4da652 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -125,7 +125,7 @@ public OpenApiOperation(OpenApiOperation operation) Parameters = operation?.Parameters != null ? new List(operation.Parameters) : null; RequestBody = operation?.RequestBody != null ? new(operation?.RequestBody) : null; Responses = operation?.Responses != null ? new(operation?.Responses) : null; - Callbacks = DictionaryCloneHelper.Clone(operation?.Callbacks); + Callbacks = operation?.Callbacks != null ? new Dictionary(operation.Callbacks) : null; Deprecated = operation?.Deprecated ?? Deprecated; Security = operation?.Security != null ? new List(operation.Security) : null; Servers = operation?.Servers != null ? new List(operation.Servers) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index e140e1f35..6c926de88 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -163,9 +163,9 @@ public OpenApiParameter(OpenApiParameter parameter) Explode = parameter?.Explode ?? Explode; AllowReserved = parameter?.AllowReserved ?? AllowReserved; Schema = parameter?.Schema != null ? new(parameter?.Schema) : null; - Examples = DictionaryCloneHelper.Clone(parameter?.Examples); + Examples = parameter?.Examples != null ? new Dictionary(parameter.Examples) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); - Content = DictionaryCloneHelper.Clone(parameter?.Content); + Content = parameter?.Content != null ? new Dictionary(parameter.Content) : null; Extensions = parameter?.Extensions != null ? new Dictionary(parameter.Extensions) : null; AllowEmptyValue = parameter?.AllowEmptyValue ?? AllowEmptyValue; Deprecated = parameter?.Deprecated ?? Deprecated; diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index a669c67bc..86ed5c4b0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -79,7 +79,7 @@ public OpenApiPathItem(OpenApiPathItem pathItem) { Summary = pathItem?.Summary ?? Summary; Description = pathItem?.Description ?? Description; - Operations = DictionaryCloneHelper.Clone(pathItem?.Operations); + Operations = pathItem?.Operations != null ? new Dictionary(pathItem.Operations) : null; Servers = pathItem?.Servers != null ? new List(pathItem.Servers) : null; Parameters = pathItem?.Parameters != null ? new List(pathItem.Parameters) : null; Extensions = pathItem?.Extensions != null ? new Dictionary(pathItem.Extensions) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs index 53f56c5ad..e73579eaf 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -22,6 +22,6 @@ public OpenApiPaths() {} /// Initializes a copy of object /// /// The . - public OpenApiPaths(OpenApiPaths paths) : base(DictionaryCloneHelper.Clone(paths)) { } + public OpenApiPaths(OpenApiPaths paths) : base(dictionary: paths) { } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 10603256c..e6abf5d5c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -62,7 +62,7 @@ public OpenApiRequestBody(OpenApiRequestBody requestBody) Reference = requestBody?.Reference != null ? new(requestBody?.Reference) : null; Description = requestBody?.Description ?? Description; Required = requestBody?.Required ?? Required; - Content = DictionaryCloneHelper.Clone(requestBody?.Content); + Content = requestBody?.Content != null ? new Dictionary(requestBody.Content) : null; Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 958f20f61..a48b14163 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -63,9 +63,9 @@ public OpenApiResponse() {} public OpenApiResponse(OpenApiResponse response) { Description = response?.Description ?? Description; - Headers = DictionaryCloneHelper.Clone(response?.Headers); - Content = DictionaryCloneHelper.Clone(response?.Content); - Links = DictionaryCloneHelper.Clone(response?.Links); + Headers = response?.Headers != null ? new Dictionary(response.Headers) : null; + Content = response?.Content != null ? new Dictionary(response.Content) : null; + Links = response?.Links != null ? new Dictionary(response.Links) : null; Extensions = response?.Extensions != null ? new Dictionary(response.Extensions) : null; UnresolvedReference = response?.UnresolvedReference ?? UnresolvedReference; Reference = response?.Reference != null ? new(response?.Reference) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs index 86b484408..b6f3d71d7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs @@ -19,6 +19,6 @@ public OpenApiResponses() { } /// Initializes a copy of object /// /// The - public OpenApiResponses(OpenApiResponses openApiResponses) : base(DictionaryCloneHelper.Clone(openApiResponses)) {} + public OpenApiResponses(OpenApiResponses openApiResponses) : base(dictionary: openApiResponses) {} } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 0b1722bc4..050c6d4bf 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -277,7 +277,7 @@ public OpenApiSchema(OpenApiSchema schema) MaxItems = schema?.MaxItems ?? MaxItems; MinItems = schema?.MinItems ?? MinItems; UniqueItems = schema?.UniqueItems ?? UniqueItems; - Properties = DictionaryCloneHelper.Clone(schema?.Properties); + Properties = schema?.Properties != null ? new Dictionary(schema.Properties) : null; MaxProperties = schema?.MaxProperties ?? MaxProperties; MinProperties = schema?.MinProperties ?? MinProperties; AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed; diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 8f9baed45..94119bc24 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -49,7 +49,7 @@ public OpenApiServer(OpenApiServer server) { Description = server?.Description ?? Description; Url = server?.Url ?? Url; - Variables = DictionaryCloneHelper.Clone(server?.Variables); + Variables = server?.Variables != null ? new Dictionary(server.Variables) : null; Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index ceed06bb9..6e3200957 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1339,26 +1339,26 @@ private static OpenApiDocument ParseInputFile(string filePath) return openApiDoc; } - [Fact] - public void CopyConstructorForAdvancedDocumentWorks() - { - // Arrange & Act - var doc = new OpenApiDocument(AdvancedDocument); - - var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; - var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; - var responseSchemaTypeCopy = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type = "object"; - var advancedDocResponseSchemaType = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type; - - // Assert - Assert.NotNull(doc.Info); - Assert.NotNull(doc.Servers); - Assert.NotNull(doc.Paths); - Assert.Equal(2, doc.Paths.Count); - Assert.NotNull(doc.Components); - Assert.NotEqual(docOpId, advancedDocOpId); - Assert.NotEqual(responseSchemaTypeCopy, advancedDocResponseSchemaType); - } + //[Fact] + //public void CopyConstructorForAdvancedDocumentWorks() + //{ + // // Arrange & Act + // var doc = new OpenApiDocument(AdvancedDocument); + + // var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; + // var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; + // var responseSchemaTypeCopy = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type = "object"; + // var advancedDocResponseSchemaType = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type; + + // // Assert + // Assert.NotNull(doc.Info); + // Assert.NotNull(doc.Servers); + // Assert.NotNull(doc.Paths); + // Assert.Equal(2, doc.Paths.Count); + // Assert.NotNull(doc.Components); + // Assert.NotEqual(docOpId, advancedDocOpId); + // Assert.NotEqual(responseSchemaTypeCopy, advancedDocResponseSchemaType); + //} [Fact] public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat() From a66db83a210ecc4915e430cda066bee14fe5159f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 17 Apr 2023 09:01:50 -0400 Subject: [PATCH 4/7] - removes unused file --- .../Helpers/DictionaryCloneHelper.cs | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs deleted file mode 100644 index ef349a477..000000000 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; - -namespace Microsoft.OpenApi.Helpers -{ - /// - /// Helper class for deep cloning dictionaries. - /// - internal static class DictionaryCloneHelper - { - /// - /// Deep clone key value pairs in a dictionary. - /// - /// The type of the key of the dictionary. - /// The type of the value of the dictionary. - /// The target dictionary to clone. - /// The cloned dictionary. - internal static Dictionary Clone(IDictionary dictionary) - { - if (dictionary is null) return null; - - var clonedDictionary = new Dictionary(dictionary.Keys.Count); - var clonedObjects = new Dictionary(); - - foreach (var keyValuePair in dictionary) - { - // If the object has already been cloned, use the cloned object instead of cloning it again - if (clonedObjects.TryGetValue(keyValuePair.Value, out var clonedValue)) - { - clonedDictionary[keyValuePair.Key] = (U)clonedValue; - } - else - { - // Create instance of the specified type using the constructor matching the specified parameter types. - clonedDictionary[keyValuePair.Key] = (U)Activator.CreateInstance(keyValuePair.Value.GetType(), keyValuePair.Value); - - // Add the cloned object to the dictionary of cloned objects - clonedObjects.Add(keyValuePair.Value, clonedDictionary[keyValuePair.Key]); - } - } - - return clonedDictionary; - } - } -} From 542a0341eacb61d6d610c13e7054575190d692ab Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 17 Apr 2023 16:10:43 +0300 Subject: [PATCH 5/7] Remove unnecessary usings --- src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs | 3 --- src/Microsoft.OpenApi/Models/OpenApiCallback.cs | 2 -- src/Microsoft.OpenApi/Models/OpenApiComponents.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiDocument.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiEncoding.cs | 2 -- src/Microsoft.OpenApi/Models/OpenApiExample.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiMediaType.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 2 -- src/Microsoft.OpenApi/Models/OpenApiPathItem.cs | 2 -- src/Microsoft.OpenApi/Models/OpenApiPaths.cs | 5 ----- src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiResponse.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiResponses.cs | 2 -- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 1 - src/Microsoft.OpenApi/Models/OpenApiServer.cs | 2 -- 16 files changed, 28 deletions(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs index 8e75c9d39..5e499ccac 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs @@ -2,9 +2,6 @@ // Licensed under the MIT license. using System.Reflection; -using Microsoft.OpenApi.Helpers; -using System.Text.Json.Serialization; -using System.Text.Json; namespace Microsoft.OpenApi.Any { diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index b25ed8578..e6aa5d075 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -2,9 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; -using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Expressions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index b8877eeff..a6bfef594 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 2bf5dd2f2..5177e4f45 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -8,7 +8,6 @@ using System.Security.Cryptography; using System.Text; using Microsoft.OpenApi.Exceptions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Services; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index e039a04ee..13b6e3a0a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -2,9 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; -using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index d8ac064c0..4d091a361 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 359c1c70c..fb4411478 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 276cc3807..63a58cd02 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 6c926de88..2efd0c747 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -3,10 +3,8 @@ using System; using System.Collections.Generic; -using System.Runtime; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 86ed5c4b0..ddd358dc2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -1,10 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs index e73579eaf..8aae74883 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -1,11 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; -using System.Collections; -using System.Collections.Generic; -using Microsoft.OpenApi.Helpers; - namespace Microsoft.OpenApi.Models { /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index e6abf5d5c..70f1f742a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index a48b14163..a173f6c1a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs index b6f3d71d7..aa7a8c984 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using Microsoft.OpenApi.Helpers; - namespace Microsoft.OpenApi.Models { /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 050c6d4bf..0176ea1d9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 94119bc24..a13a6fb2d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; From 6eac7c0211f2b01331d90018475bed9d5966b09d Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 17 Apr 2023 16:24:29 +0300 Subject: [PATCH 6/7] Remove unnecesary using; bump lib versions --- src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- src/Microsoft.OpenApi/Models/OpenApiOperation.cs | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index b3c482215..9651dd6d7 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -10,7 +10,7 @@ Microsoft Microsoft.OpenApi.Readers Microsoft.OpenApi.Readers - 1.6.4-preview3 + 1.6.4-preview4 OpenAPI.NET Readers for JSON and YAML documents © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index ba72031e6..3a72d738e 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -11,7 +11,7 @@ Microsoft Microsoft.OpenApi Microsoft.OpenApi - 1.6.4-preview3 + 1.6.4-preview4 .NET models with JSON and YAML writers for OpenAPI specification © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index a1c4da652..9336662d8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; From 67245931a3e438de296842740180956166a0f6eb Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 17 Apr 2023 16:27:00 +0300 Subject: [PATCH 7/7] clean up --- src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs index 5e499ccac..e34fb8cbf 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs @@ -29,7 +29,7 @@ public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj) } } } - + return obj; } } diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 3a72d738e..00d336626 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -33,9 +33,6 @@ true - - -