From 345f13602c512a29f4418acc005cfb52cb1d53fd Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Tue, 28 Mar 2023 13:03:03 +0300 Subject: [PATCH 01/21] Add unit test to break copy constructors --- test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index c4876db7a..a1d7cc665 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1344,12 +1344,18 @@ public void CopyConstructorForAdvancedDocumentWorks() // Arrange & Act var doc = new OpenApiDocument(AdvancedDocument); + // Change value of operation id for a given url + // doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; + var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; + var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; + // 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); } [Fact] From d5a5f8a8890825824f31187355850945416aa7ea Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Tue, 28 Mar 2023 14:15:54 +0300 Subject: [PATCH 02/21] Remove commented code --- test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index a1d7cc665..68bb0e037 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1345,7 +1345,6 @@ public void CopyConstructorForAdvancedDocumentWorks() var doc = new OpenApiDocument(AdvancedDocument); // Change value of operation id for a given url - // doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; From e518515584fd3713fc00efcea2c907ed1745c0be Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 3 Apr 2023 15:40:34 +0300 Subject: [PATCH 03/21] Adds a dictionary clone helper to help us deep clone all the values of the key value pairs in a dictionary --- .../Helpers/DictionaryCloneHelper.cs | 37 +++++++++++++++++++ .../Models/OpenApiOperation.cs | 3 +- .../Models/OpenApiPathItem.cs | 4 +- src/Microsoft.OpenApi/Models/OpenApiPaths.cs | 7 +++- .../Models/OpenApiResponses.cs | 4 +- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs new file mode 100644 index 000000000..13d32e184 --- /dev/null +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -0,0 +1,37 @@ +// 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. + /// + public class DictionaryCloneHelper + { + /// + /// Deep clone key value pairs in a dictionary. + /// + /// + /// + /// + /// + public static Dictionary Clone(IDictionary dictionary) + { + var clonedDictionary = new Dictionary(); + + if (dictionary != null) + { + foreach (var kvp in dictionary) + { + // Create instance of the specified type using the constructor matching the specified parameter types. + clonedDictionary[kvp.Key] = (U)Activator.CreateInstance(kvp.Value.GetType(), kvp.Value); + } + } + + return clonedDictionary; + } + } +} diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index d047b9cb6..d46dc598e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -124,7 +125,7 @@ public OpenApiOperation(OpenApiOperation operation) Parameters = operation?.Parameters != null ? new List(operation.Parameters) : null; RequestBody = new(operation?.RequestBody); Responses = operation?.Responses != null ? new(operation?.Responses) : null; - Callbacks = operation?.Callbacks != null ? new Dictionary(operation.Callbacks) : null; + Callbacks = operation?.Callbacks != null ? DictionaryCloneHelper.Clone(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/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index ddd358dc2..61de36c7c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -1,8 +1,10 @@ // 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; @@ -77,7 +79,7 @@ public OpenApiPathItem(OpenApiPathItem pathItem) { Summary = pathItem?.Summary ?? Summary; Description = pathItem?.Description ?? Description; - Operations = pathItem?.Operations != null ? new Dictionary(pathItem.Operations) : null; + Operations = pathItem?.Operations != null ? DictionaryCloneHelper.Clone(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 9b48b4908..53f56c5ad 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPaths.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPaths.cs @@ -1,6 +1,11 @@ // 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 { /// @@ -17,6 +22,6 @@ public OpenApiPaths() {} /// Initializes a copy of object /// /// The . - public OpenApiPaths(OpenApiPaths paths) : base(dictionary: paths) {} + public OpenApiPaths(OpenApiPaths paths) : base(DictionaryCloneHelper.Clone(paths)) { } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs index aa7a8c984..86b484408 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponses.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponses.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using Microsoft.OpenApi.Helpers; + namespace Microsoft.OpenApi.Models { /// @@ -17,6 +19,6 @@ public OpenApiResponses() { } /// Initializes a copy of object /// /// The - public OpenApiResponses(OpenApiResponses openApiResponses) : base(dictionary: openApiResponses) {} + public OpenApiResponses(OpenApiResponses openApiResponses) : base(DictionaryCloneHelper.Clone(openApiResponses)) {} } } From b1f06d75c239e7113fcdcc9136734603bb125ee7 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 3 Apr 2023 15:40:53 +0300 Subject: [PATCH 04/21] Add test suite; update public API --- .../Models/OpenApiDocumentTests.cs | 5 ++++- .../PublicApi/PublicApi.approved.txt | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 68bb0e037..8450da0b0 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -12,6 +12,7 @@ using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers; +using Microsoft.OpenApi.Services; using Microsoft.OpenApi.Writers; using VerifyXunit; using Xunit; @@ -1344,9 +1345,10 @@ public void CopyConstructorForAdvancedDocumentWorks() // Arrange & Act var doc = new OpenApiDocument(AdvancedDocument); - // Change value of operation id for a given url var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; + var docResponse = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Description = "MyPet"; + var advancedDocResponse = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Description; // Assert Assert.NotNull(doc.Info); @@ -1355,6 +1357,7 @@ public void CopyConstructorForAdvancedDocumentWorks() Assert.Equal(2, doc.Paths.Count); Assert.NotNull(doc.Components); Assert.NotEqual(docOpId, advancedDocOpId); + Assert.NotEqual(docResponse, advancedDocResponse); } [Fact] diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 63cd0f535..d66155389 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -292,6 +292,14 @@ namespace Microsoft.OpenApi.Extensions public static T GetEnumFromDisplayName(this string displayName) { } } } +namespace Microsoft.OpenApi.Helpers +{ + public class DictionaryCloneHelper + { + public DictionaryCloneHelper() { } + public static System.Collections.Generic.Dictionary Clone(System.Collections.Generic.IDictionary dictionary) { } + } +} namespace Microsoft.OpenApi.Interfaces { public interface IEffective @@ -587,6 +595,7 @@ namespace Microsoft.OpenApi.Models { protected OpenApiExtensibleDictionary() { } protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary = null, System.Collections.Generic.IDictionary extensions = null) { } + public System.Collections.Generic.IDictionary Dictionary { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } From 8a93c141697f83b8e998ae9be78651eac26abe27 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 3 Apr 2023 17:08:18 +0300 Subject: [PATCH 05/21] Use DictionaryCloneHelper --- src/Microsoft.OpenApi/Models/OpenApiDocument.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 5177e4f45..f80e976cb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -8,6 +8,7 @@ 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; @@ -88,7 +89,7 @@ public OpenApiDocument(OpenApiDocument document) SecurityRequirements = document?.SecurityRequirements != null ? new List(document.SecurityRequirements) : null; Tags = document?.Tags != null ? new List(document.Tags) : null; ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null; - Extensions = document?.Extensions != null ? new Dictionary(document.Extensions) : null; + Extensions = document?.Extensions != null ? DictionaryCloneHelper.Clone(document.Extensions) : null; } /// From 608d908664008641983f76a0b764cb1789a92007 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 3 Apr 2023 17:10:45 +0300 Subject: [PATCH 06/21] Updates XML summary --- src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs index 13d32e184..80ae9af67 100644 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -14,10 +14,10 @@ public 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. public static Dictionary Clone(IDictionary dictionary) { var clonedDictionary = new Dictionary(); From be998b06d4f7a79fd30bacce587e9a0db1920a8e Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 3 Apr 2023 17:24:16 +0300 Subject: [PATCH 07/21] Use DictionaryCloneHelper cloning method for all dictionary copies --- src/Microsoft.OpenApi/Models/OpenApiEncoding.cs | 5 +++-- src/Microsoft.OpenApi/Models/OpenApiExample.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 7 ++++--- src/Microsoft.OpenApi/Models/OpenApiMediaType.cs | 7 ++++--- src/Microsoft.OpenApi/Models/OpenApiResponse.cs | 9 +++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index ddb4162bc..d16b6bb56 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -64,11 +65,11 @@ public OpenApiEncoding() {} public OpenApiEncoding(OpenApiEncoding encoding) { ContentType = encoding?.ContentType ?? ContentType; - Headers = encoding?.Headers != null ? new Dictionary(encoding.Headers) : null; + Headers = encoding?.Headers != null ? DictionaryCloneHelper.Clone(encoding.Headers) : null; Style = encoding?.Style ?? Style; Explode = encoding?.Explode ?? Explode; AllowReserved = encoding?.AllowReserved ?? AllowReserved; - Extensions = encoding?.Extensions != null ? new Dictionary(encoding.Extensions) : null; + Extensions = encoding?.Extensions != null ? DictionaryCloneHelper.Clone(encoding.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 4d091a361..722e1e0d8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -68,7 +69,7 @@ public OpenApiExample(OpenApiExample example) Description = example?.Description ?? Description; Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); ExternalValue = example?.ExternalValue ?? ExternalValue; - Extensions = example?.Extensions != null ? new Dictionary(example.Extensions) : null; + Extensions = example?.Extensions != null ? DictionaryCloneHelper.Clone(example.Extensions) : null; Reference = example?.Reference != null ? new(example?.Reference) : null; UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index fb4411478..6277a24b7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -107,9 +108,9 @@ public OpenApiHeader(OpenApiHeader header) AllowReserved = header?.AllowReserved ?? AllowReserved; Schema = header?.Schema != null ? new(header?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example); - Examples = header?.Examples != null ? new Dictionary(header.Examples) : null; - Content = header?.Content != null ? new Dictionary(header.Content) : null; - Extensions = header?.Extensions != null ? new Dictionary(header.Extensions) : null; + Examples = header?.Examples != null ? DictionaryCloneHelper.Clone(header.Examples) : null; + Content = header?.Content != null ? DictionaryCloneHelper.Clone(header.Content) : null; + Extensions = header?.Extensions != null ? DictionaryCloneHelper.Clone(header.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 63a58cd02..c141a36f1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -55,9 +56,9 @@ public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); - Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples) : null; - Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding) : null; - Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null; + Examples = mediaType?.Examples != null ? DictionaryCloneHelper.Clone(mediaType.Examples) : null; + Encoding = mediaType?.Encoding != null ? DictionaryCloneHelper.Clone(mediaType.Encoding) : null; + Extensions = mediaType?.Extensions != null ? DictionaryCloneHelper.Clone(mediaType.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index a173f6c1a..2d4a7ac3e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -62,10 +63,10 @@ public OpenApiResponse() {} public OpenApiResponse(OpenApiResponse response) { Description = response?.Description ?? Description; - Headers = response?.Headers != null ? new Dictionary(response.Headers) : null; - Content = response?.Content != null ? new Dictionary(response.Content) : null; - Links = response?.Links != null ? new Dictionary(response.Links) : null; - Extensions = response?.Extensions != null ? new Dictionary(response.Extensions) : null; + Headers = response?.Headers != null ? DictionaryCloneHelper.Clone(response.Headers) : null; + Content = response?.Content != null ? DictionaryCloneHelper.Clone(response.Content) : null; + Links = response?.Links != null ? DictionaryCloneHelper.Clone(response.Links) : null; + Extensions = response?.Extensions != null ? DictionaryCloneHelper.Clone(response.Extensions) : null; UnresolvedReference = response?.UnresolvedReference ?? UnresolvedReference; Reference = response?.Reference != null ? new(response?.Reference) : null; } From 8d835728baf9457240279109f0a1d8ac2721d29e Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 3 Apr 2023 17:24:34 +0300 Subject: [PATCH 08/21] Add test case for content media type --- test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 8450da0b0..ceed06bb9 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1347,8 +1347,8 @@ public void CopyConstructorForAdvancedDocumentWorks() var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; - var docResponse = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Description = "MyPet"; - var advancedDocResponse = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Description; + 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); @@ -1357,7 +1357,7 @@ public void CopyConstructorForAdvancedDocumentWorks() Assert.Equal(2, doc.Paths.Count); Assert.NotNull(doc.Components); Assert.NotEqual(docOpId, advancedDocOpId); - Assert.NotEqual(docResponse, advancedDocResponse); + Assert.NotEqual(responseSchemaTypeCopy, advancedDocResponseSchemaType); } [Fact] From 6a65cf4c02b13eee81d076c82dcd2214bf65bb0a Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 3 Apr 2023 17:28:52 +0300 Subject: [PATCH 09/21] Update public API --- test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index d66155389..df9ef4393 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -595,7 +595,6 @@ namespace Microsoft.OpenApi.Models { protected OpenApiExtensibleDictionary() { } protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary = null, System.Collections.Generic.IDictionary extensions = null) { } - public System.Collections.Generic.IDictionary Dictionary { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } From 264611d48707c3367e07e44597e229bc8c0cc896 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 3 Apr 2023 18:40:56 +0300 Subject: [PATCH 10/21] Use DictionaryCloneHelper.Clone() method --- .../Models/OpenApiComponents.cs | 23 +++++++++---------- .../Models/OpenApiParameter.cs | 7 +++--- .../Models/OpenApiRequestBody.cs | 5 ++-- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 5 ++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 1f41080bc..dd6ee8914 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -1,10 +1,9 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -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; @@ -78,15 +77,15 @@ public OpenApiComponents() { } /// public OpenApiComponents(OpenApiComponents components) { - 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; + Schemas = components?.Schemas != null ? DictionaryCloneHelper.Clone(components.Schemas) : null; + Responses = components?.Responses != null ? DictionaryCloneHelper.Clone(components.Responses) : null; + Parameters = components?.Parameters != null ? DictionaryCloneHelper.Clone(components.Parameters) : null; + Examples = components?.Examples != null ? DictionaryCloneHelper.Clone(components.Examples) : null; + RequestBodies = components?.RequestBodies != null ? DictionaryCloneHelper.Clone(components.RequestBodies) : null; + Headers = components?.Headers != null ? DictionaryCloneHelper.Clone(components.Headers) : null; + SecuritySchemes = components?.SecuritySchemes != null ? DictionaryCloneHelper.Clone(components.SecuritySchemes) : null; + Links = components?.Links != null ? DictionaryCloneHelper.Clone(components.Links) : null; + Callbacks = components?.Callbacks != null ? DictionaryCloneHelper.Clone(components.Callbacks) : null; Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index fa62f0b79..061081752 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -6,6 +6,7 @@ using System.Runtime; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -162,9 +163,9 @@ public OpenApiParameter(OpenApiParameter parameter) Explode = parameter?.Explode ?? Explode; AllowReserved = parameter?.AllowReserved ?? AllowReserved; Schema = parameter?.Schema != null ? new(parameter?.Schema) : null; - Examples = parameter?.Examples != null ? new Dictionary(parameter.Examples) : null; + Examples = parameter?.Examples != null ? DictionaryCloneHelper.Clone(parameter.Examples) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); - Content = parameter?.Content != null ? new Dictionary(parameter.Content) : null; + Content = parameter?.Content != null ? DictionaryCloneHelper.Clone(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/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 70f1f742a..1209c33c7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. 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; @@ -61,7 +62,7 @@ public OpenApiRequestBody(OpenApiRequestBody requestBody) Reference = requestBody?.Reference != null ? new(requestBody?.Reference) : null; Description = requestBody?.Description ?? Description; Required = requestBody?.Required ?? Required; - Content = requestBody?.Content != null ? new Dictionary(requestBody.Content) : null; + Content = requestBody?.Content != null ? DictionaryCloneHelper.Clone(requestBody.Content) : null; Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index b3b1d1287..d009e7a14 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -1,8 +1,9 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // 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; @@ -48,7 +49,7 @@ public OpenApiServer(OpenApiServer server) { Description = server?.Description ?? Description; Url = server?.Url ?? Url; - Variables = server?.Variables != null ? new Dictionary(server.Variables) : null; + Variables = server?.Variables != null ? DictionaryCloneHelper.Clone(server.Variables) : null; Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } From 08acaaa791194bcee20bea329e1901b894db8b27 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Tue, 4 Apr 2023 10:25:18 +0300 Subject: [PATCH 11/21] Clean up dictionary cloning logic --- src/Microsoft.OpenApi/Models/OpenApiComponents.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiContact.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiLicense.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs | 5 +++-- src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiOperation.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiPathItem.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 3 ++- 18 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index dd6ee8914..5c4a56d56 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -86,7 +86,7 @@ public OpenApiComponents(OpenApiComponents components) SecuritySchemes = components?.SecuritySchemes != null ? DictionaryCloneHelper.Clone(components.SecuritySchemes) : null; Links = components?.Links != null ? DictionaryCloneHelper.Clone(components.Links) : null; Callbacks = components?.Callbacks != null ? DictionaryCloneHelper.Clone(components.Callbacks) : null; - Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; + Extensions = components?.Extensions != null ? DictionaryCloneHelper.Clone(components.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 93cb11bca..1d89237e3 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -48,7 +49,7 @@ public OpenApiContact(OpenApiContact contact) Name = contact?.Name ?? Name; Url = contact?.Url != null ? new Uri(contact.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; Email = contact?.Email ?? Email; - Extensions = contact?.Extensions != null ? new Dictionary(contact.Extensions) : null; + Extensions = contact?.Extensions != null ? DictionaryCloneHelper.Clone(contact.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs index 40c26d429..b07cca7c6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -30,7 +31,7 @@ protected OpenApiExtensibleDictionary( Dictionary dictionary = null, IDictionary extensions = null) : base (dictionary) { - Extensions = extensions != null ? new Dictionary(extensions) : null; + Extensions = extensions != null ? DictionaryCloneHelper.Clone(extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 345f07d59..4a438de8f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -41,7 +42,7 @@ public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { Description = externalDocs?.Description ?? Description; Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs.Extensions) : null; + Extensions = externalDocs?.Extensions != null ? DictionaryCloneHelper.Clone(externalDocs.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index df0aa0a49..08548310f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -65,7 +66,7 @@ public OpenApiInfo(OpenApiInfo info) TermsOfService = info?.TermsOfService ?? TermsOfService; Contact = info?.Contact != null ? new(info?.Contact) : null; License = info?.License != null ? new(info?.License) : null; - Extensions = info?.Extensions != null ? new Dictionary(info.Extensions) : null; + Extensions = info?.Extensions != null ? DictionaryCloneHelper.Clone(info.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 866515835..0ea58e333 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -41,7 +42,7 @@ public OpenApiLicense(OpenApiLicense license) { Name = license?.Name ?? Name; Url = license?.Url != null ? new Uri(license.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = license?.Extensions != null ? new Dictionary(license.Extensions) : null; + Extensions = license?.Extensions != null ? DictionaryCloneHelper.Clone(license.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index b682744e9..5d9e1b5e1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -77,7 +78,7 @@ public OpenApiLink(OpenApiLink link) RequestBody = link?.RequestBody != null ? new(link?.RequestBody) : null; Description = link?.Description ?? Description; Server = link?.Server != null ? new(link?.Server) : null; - Extensions = link?.Extensions != null ? new Dictionary(link.Extensions) : null; + Extensions = link?.Extensions != null ? DictionaryCloneHelper.Clone(link.Extensions) : null; UnresolvedReference = link?.UnresolvedReference ?? UnresolvedReference; Reference = link?.Reference != null ? new(link?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 9c12fb5a9..f71e7eaf2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -54,8 +55,8 @@ public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; - Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow.Scopes) : null; - Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow.Extensions) : null; + Scopes = oAuthFlow?.Scopes != null ? DictionaryCloneHelper.Clone(oAuthFlow.Scopes) : null; + Extensions = oAuthFlow?.Extensions != null ? DictionaryCloneHelper.Clone(oAuthFlow.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index 8443e6730..b8cb626e8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -53,7 +54,7 @@ public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) Password = oAuthFlows?.Password != null ? new(oAuthFlows?.Password) : null; ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows?.ClientCredentials) : null; AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows?.AuthorizationCode) : null; - Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows.Extensions) : null; + Extensions = oAuthFlows?.Extensions != null ? DictionaryCloneHelper.Clone(oAuthFlows.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index d46dc598e..cabb61d68 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -129,7 +129,7 @@ public OpenApiOperation(OpenApiOperation operation) Deprecated = operation?.Deprecated ?? Deprecated; Security = operation?.Security != null ? new List(operation.Security) : null; Servers = operation?.Servers != null ? new List(operation.Servers) : null; - Extensions = operation?.Extensions != null ? new Dictionary(operation.Extensions) : null; + Extensions = operation?.Extensions != null ? DictionaryCloneHelper.Clone(operation.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 061081752..16e9a32c1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -166,7 +166,7 @@ public OpenApiParameter(OpenApiParameter parameter) Examples = parameter?.Examples != null ? DictionaryCloneHelper.Clone(parameter.Examples) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); Content = parameter?.Content != null ? DictionaryCloneHelper.Clone(parameter.Content) : null; - Extensions = parameter?.Extensions != null ? new Dictionary(parameter.Extensions) : null; + Extensions = parameter?.Extensions != null ? DictionaryCloneHelper.Clone(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 61de36c7c..c0e93cad4 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -82,7 +82,7 @@ public OpenApiPathItem(OpenApiPathItem pathItem) Operations = pathItem?.Operations != null ? DictionaryCloneHelper.Clone(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; + Extensions = pathItem?.Extensions != null ? DictionaryCloneHelper.Clone(pathItem.Extensions) : null; UnresolvedReference = pathItem?.UnresolvedReference ?? UnresolvedReference; Reference = pathItem?.Reference != null ? new(pathItem?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 1209c33c7..f437f9097 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -63,7 +63,7 @@ public OpenApiRequestBody(OpenApiRequestBody requestBody) Description = requestBody?.Description ?? Description; Required = requestBody?.Required ?? Required; Content = requestBody?.Content != null ? DictionaryCloneHelper.Clone(requestBody.Content) : null; - Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody.Extensions) : null; + Extensions = requestBody?.Extensions != null ? DictionaryCloneHelper.Clone(requestBody.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index 616a6a022..de924ff7e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -6,6 +6,7 @@ using System.Linq; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -92,7 +93,7 @@ public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) BearerFormat = securityScheme?.BearerFormat ?? BearerFormat; Flows = securityScheme?.Flows != null ? new(securityScheme?.Flows) : null; OpenIdConnectUrl = securityScheme?.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = securityScheme?.Extensions != null ? new Dictionary(securityScheme.Extensions) : null; + Extensions = securityScheme?.Extensions != null ? DictionaryCloneHelper.Clone(securityScheme.Extensions) : null; UnresolvedReference = securityScheme?.UnresolvedReference ?? UnresolvedReference; Reference = securityScheme?.Reference != null ? new(securityScheme?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index d009e7a14..a736543a2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -50,7 +50,7 @@ public OpenApiServer(OpenApiServer server) Description = server?.Description ?? Description; Url = server?.Url ?? Url; Variables = server?.Variables != null ? DictionaryCloneHelper.Clone(server.Variables) : null; - Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; + Extensions = server?.Extensions != null ? DictionaryCloneHelper.Clone(server.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 70164bc59..a78759310 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -47,7 +48,7 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) Description = serverVariable?.Description; Default = serverVariable?.Default; Enum = serverVariable?.Enum != null ? new List(serverVariable?.Enum) : serverVariable?.Enum; - Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable?.Extensions) : serverVariable?.Extensions; + Extensions = serverVariable?.Extensions != null ? DictionaryCloneHelper.Clone(serverVariable?.Extensions) : serverVariable?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index ba4129142..78003c4a1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -56,7 +57,7 @@ public OpenApiTag(OpenApiTag tag) Name = tag?.Name ?? Name; Description = tag?.Description ?? Description; ExternalDocs = tag?.ExternalDocs != null ? new(tag?.ExternalDocs) : null; - Extensions = tag?.Extensions != null ? new Dictionary(tag.Extensions) : null; + Extensions = tag?.Extensions != null ? DictionaryCloneHelper.Clone(tag.Extensions) : null; UnresolvedReference = tag?.UnresolvedReference ?? UnresolvedReference; Reference = tag?.Reference != null ? new(tag?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index c6719d85e..7a2f2cde8 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -61,7 +62,7 @@ public OpenApiXml(OpenApiXml xml) Prefix = xml?.Prefix ?? Prefix; Attribute = xml?.Attribute ?? Attribute; Wrapped = xml?.Wrapped ?? Wrapped; - Extensions = xml?.Extensions != null ? new Dictionary(xml.Extensions) : null; + Extensions = xml?.Extensions != null ? DictionaryCloneHelper.Clone(xml.Extensions) : null; } /// From 9af76212e48bf7555bb2b586ca5d1497d57edef7 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Tue, 4 Apr 2023 10:26:42 +0300 Subject: [PATCH 12/21] Clean up code --- src/Microsoft.OpenApi/Models/OpenApiCallback.cs | 3 ++- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 2dcae12d1..b300a7215 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Expressions; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -48,7 +49,7 @@ public OpenApiCallback(OpenApiCallback callback) PathItems = callback?.PathItems != null ? new(callback?.PathItems) : null; UnresolvedReference = callback?.UnresolvedReference ?? UnresolvedReference; Reference = callback?.Reference != null ? new(callback?.Reference) : null; - Extensions = callback?.Extensions != null ? new Dictionary(callback.Extensions) : null; + Extensions = callback?.Extensions != null ? DictionaryCloneHelper.Clone(callback.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 0176ea1d9..ddb916404 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -276,7 +277,7 @@ public OpenApiSchema(OpenApiSchema schema) MaxItems = schema?.MaxItems ?? MaxItems; MinItems = schema?.MinItems ?? MinItems; UniqueItems = schema?.UniqueItems ?? UniqueItems; - Properties = schema?.Properties != null ? new Dictionary(schema.Properties) : null; + Properties = schema?.Properties != null ? DictionaryCloneHelper.Clone(schema.Properties) : null; MaxProperties = schema?.MaxProperties ?? MaxProperties; MinProperties = schema?.MinProperties ?? MinProperties; AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed; From da9cd6af867f4f9f69e2bc70fad46b8b1e5b7c04 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Tue, 4 Apr 2023 10:25:18 +0300 Subject: [PATCH 13/21] Revert "Clean up dictionary cloning logic " This reverts commit 08acaaa791194bcee20bea329e1901b894db8b27. --- src/Microsoft.OpenApi/Models/OpenApiComponents.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiContact.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiLicense.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs | 5 ++--- src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiOperation.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiPathItem.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 3 +-- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 3 +-- 18 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 5c4a56d56..dd6ee8914 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -86,7 +86,7 @@ public OpenApiComponents(OpenApiComponents components) SecuritySchemes = components?.SecuritySchemes != null ? DictionaryCloneHelper.Clone(components.SecuritySchemes) : null; Links = components?.Links != null ? DictionaryCloneHelper.Clone(components.Links) : null; Callbacks = components?.Callbacks != null ? DictionaryCloneHelper.Clone(components.Callbacks) : null; - Extensions = components?.Extensions != null ? DictionaryCloneHelper.Clone(components.Extensions) : null; + Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 1d89237e3..93cb11bca 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -49,7 +48,7 @@ public OpenApiContact(OpenApiContact contact) Name = contact?.Name ?? Name; Url = contact?.Url != null ? new Uri(contact.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; Email = contact?.Email ?? Email; - Extensions = contact?.Extensions != null ? DictionaryCloneHelper.Clone(contact.Extensions) : null; + Extensions = contact?.Extensions != null ? new Dictionary(contact.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs index b07cca7c6..40c26d429 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. using System.Collections.Generic; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -31,7 +30,7 @@ protected OpenApiExtensibleDictionary( Dictionary dictionary = null, IDictionary extensions = null) : base (dictionary) { - Extensions = extensions != null ? DictionaryCloneHelper.Clone(extensions) : null; + Extensions = extensions != null ? new Dictionary(extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 4a438de8f..345f07d59 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -42,7 +41,7 @@ public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { Description = externalDocs?.Description ?? Description; Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = externalDocs?.Extensions != null ? DictionaryCloneHelper.Clone(externalDocs.Extensions) : null; + Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 08548310f..df0aa0a49 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -66,7 +65,7 @@ public OpenApiInfo(OpenApiInfo info) TermsOfService = info?.TermsOfService ?? TermsOfService; Contact = info?.Contact != null ? new(info?.Contact) : null; License = info?.License != null ? new(info?.License) : null; - Extensions = info?.Extensions != null ? DictionaryCloneHelper.Clone(info.Extensions) : null; + Extensions = info?.Extensions != null ? new Dictionary(info.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 0ea58e333..866515835 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -42,7 +41,7 @@ public OpenApiLicense(OpenApiLicense license) { Name = license?.Name ?? Name; Url = license?.Url != null ? new Uri(license.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = license?.Extensions != null ? DictionaryCloneHelper.Clone(license.Extensions) : null; + Extensions = license?.Extensions != null ? new Dictionary(license.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 5d9e1b5e1..b682744e9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.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; @@ -78,7 +77,7 @@ public OpenApiLink(OpenApiLink link) RequestBody = link?.RequestBody != null ? new(link?.RequestBody) : null; Description = link?.Description ?? Description; Server = link?.Server != null ? new(link?.Server) : null; - Extensions = link?.Extensions != null ? DictionaryCloneHelper.Clone(link.Extensions) : null; + Extensions = link?.Extensions != null ? new Dictionary(link.Extensions) : null; UnresolvedReference = link?.UnresolvedReference ?? UnresolvedReference; Reference = link?.Reference != null ? new(link?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index f71e7eaf2..9c12fb5a9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -55,8 +54,8 @@ public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; - Scopes = oAuthFlow?.Scopes != null ? DictionaryCloneHelper.Clone(oAuthFlow.Scopes) : null; - Extensions = oAuthFlow?.Extensions != null ? DictionaryCloneHelper.Clone(oAuthFlow.Extensions) : null; + Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow.Scopes) : null; + Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index b8cb626e8..8443e6730 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.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; @@ -54,7 +53,7 @@ public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) Password = oAuthFlows?.Password != null ? new(oAuthFlows?.Password) : null; ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows?.ClientCredentials) : null; AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows?.AuthorizationCode) : null; - Extensions = oAuthFlows?.Extensions != null ? DictionaryCloneHelper.Clone(oAuthFlows.Extensions) : null; + Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index cabb61d68..d46dc598e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -129,7 +129,7 @@ public OpenApiOperation(OpenApiOperation operation) Deprecated = operation?.Deprecated ?? Deprecated; Security = operation?.Security != null ? new List(operation.Security) : null; Servers = operation?.Servers != null ? new List(operation.Servers) : null; - Extensions = operation?.Extensions != null ? DictionaryCloneHelper.Clone(operation.Extensions) : null; + Extensions = operation?.Extensions != null ? new Dictionary(operation.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 16e9a32c1..061081752 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -166,7 +166,7 @@ public OpenApiParameter(OpenApiParameter parameter) Examples = parameter?.Examples != null ? DictionaryCloneHelper.Clone(parameter.Examples) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); Content = parameter?.Content != null ? DictionaryCloneHelper.Clone(parameter.Content) : null; - Extensions = parameter?.Extensions != null ? DictionaryCloneHelper.Clone(parameter.Extensions) : 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 c0e93cad4..61de36c7c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -82,7 +82,7 @@ public OpenApiPathItem(OpenApiPathItem pathItem) Operations = pathItem?.Operations != null ? DictionaryCloneHelper.Clone(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 ? DictionaryCloneHelper.Clone(pathItem.Extensions) : null; + Extensions = pathItem?.Extensions != null ? new Dictionary(pathItem.Extensions) : null; UnresolvedReference = pathItem?.UnresolvedReference ?? UnresolvedReference; Reference = pathItem?.Reference != null ? new(pathItem?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index f437f9097..1209c33c7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -63,7 +63,7 @@ public OpenApiRequestBody(OpenApiRequestBody requestBody) Description = requestBody?.Description ?? Description; Required = requestBody?.Required ?? Required; Content = requestBody?.Content != null ? DictionaryCloneHelper.Clone(requestBody.Content) : null; - Extensions = requestBody?.Extensions != null ? DictionaryCloneHelper.Clone(requestBody.Extensions) : null; + Extensions = requestBody?.Extensions != null ? new Dictionary(requestBody.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index de924ff7e..616a6a022 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -6,7 +6,6 @@ using System.Linq; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -93,7 +92,7 @@ public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme) BearerFormat = securityScheme?.BearerFormat ?? BearerFormat; Flows = securityScheme?.Flows != null ? new(securityScheme?.Flows) : null; OpenIdConnectUrl = securityScheme?.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = securityScheme?.Extensions != null ? DictionaryCloneHelper.Clone(securityScheme.Extensions) : null; + Extensions = securityScheme?.Extensions != null ? new Dictionary(securityScheme.Extensions) : null; UnresolvedReference = securityScheme?.UnresolvedReference ?? UnresolvedReference; Reference = securityScheme?.Reference != null ? new(securityScheme?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index a736543a2..d009e7a14 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -50,7 +50,7 @@ public OpenApiServer(OpenApiServer server) Description = server?.Description ?? Description; Url = server?.Url ?? Url; Variables = server?.Variables != null ? DictionaryCloneHelper.Clone(server.Variables) : null; - Extensions = server?.Extensions != null ? DictionaryCloneHelper.Clone(server.Extensions) : null; + Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index a78759310..70164bc59 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.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; @@ -48,7 +47,7 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) Description = serverVariable?.Description; Default = serverVariable?.Default; Enum = serverVariable?.Enum != null ? new List(serverVariable?.Enum) : serverVariable?.Enum; - Extensions = serverVariable?.Extensions != null ? DictionaryCloneHelper.Clone(serverVariable?.Extensions) : serverVariable?.Extensions; + Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable?.Extensions) : serverVariable?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 78003c4a1..ba4129142 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.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; @@ -57,7 +56,7 @@ public OpenApiTag(OpenApiTag tag) Name = tag?.Name ?? Name; Description = tag?.Description ?? Description; ExternalDocs = tag?.ExternalDocs != null ? new(tag?.ExternalDocs) : null; - Extensions = tag?.Extensions != null ? DictionaryCloneHelper.Clone(tag.Extensions) : null; + Extensions = tag?.Extensions != null ? new Dictionary(tag.Extensions) : null; UnresolvedReference = tag?.UnresolvedReference ?? UnresolvedReference; Reference = tag?.Reference != null ? new(tag?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index 7a2f2cde8..c6719d85e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -62,7 +61,7 @@ public OpenApiXml(OpenApiXml xml) Prefix = xml?.Prefix ?? Prefix; Attribute = xml?.Attribute ?? Attribute; Wrapped = xml?.Wrapped ?? Wrapped; - Extensions = xml?.Extensions != null ? DictionaryCloneHelper.Clone(xml.Extensions) : null; + Extensions = xml?.Extensions != null ? new Dictionary(xml.Extensions) : null; } /// From b97ef997e608a31af406f0f3819b088b4c4dc45b Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Wed, 5 Apr 2023 14:54:33 +0300 Subject: [PATCH 14/21] Code cleanup --- src/Microsoft.OpenApi/Models/OpenApiCallback.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index b300a7215..b25ed8578 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -49,7 +49,7 @@ public OpenApiCallback(OpenApiCallback callback) PathItems = callback?.PathItems != null ? new(callback?.PathItems) : null; UnresolvedReference = callback?.UnresolvedReference ?? UnresolvedReference; Reference = callback?.Reference != null ? new(callback?.Reference) : null; - Extensions = callback?.Extensions != null ? DictionaryCloneHelper.Clone(callback.Extensions) : null; + Extensions = callback?.Extensions != null ? new Dictionary(callback.Extensions) : null; } /// From fb297a105c1f20a93feb05990959b1ce6f865f0e Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 6 Apr 2023 15:26:19 +0300 Subject: [PATCH 15/21] Address PR feedback --- .../Helpers/DictionaryCloneHelper.cs | 8 ++++---- .../Models/OpenApiComponents.cs | 20 +++++++++---------- .../Models/OpenApiDocument.cs | 2 +- .../Models/OpenApiEncoding.cs | 4 ++-- .../Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 6 +++--- .../Models/OpenApiMediaType.cs | 6 +++--- .../Models/OpenApiOperation.cs | 2 +- .../Models/OpenApiParameter.cs | 6 +++--- .../Models/OpenApiPathItem.cs | 2 +- .../Models/OpenApiRequestBody.cs | 4 ++-- .../Models/OpenApiResponse.cs | 8 ++++---- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 4 ++-- 14 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs index 80ae9af67..bda087d08 100644 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.Helpers /// /// Helper class for deep cloning dictionaries. /// - public class DictionaryCloneHelper + internal class DictionaryCloneHelper { /// /// Deep clone key value pairs in a dictionary. @@ -18,9 +18,9 @@ public class DictionaryCloneHelper /// The type of the value of the dictionary. /// The target dictionary to clone. /// The cloned dictionary. - public static Dictionary Clone(IDictionary dictionary) - { - var clonedDictionary = new Dictionary(); + internal static Dictionary Clone(IDictionary dictionary) + { + var clonedDictionary = dictionary is null ? null : new Dictionary(); if (dictionary != null) { diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index dd6ee8914..1b1b91abe 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -77,15 +77,15 @@ public OpenApiComponents() { } /// public OpenApiComponents(OpenApiComponents components) { - Schemas = components?.Schemas != null ? DictionaryCloneHelper.Clone(components.Schemas) : null; - Responses = components?.Responses != null ? DictionaryCloneHelper.Clone(components.Responses) : null; - Parameters = components?.Parameters != null ? DictionaryCloneHelper.Clone(components.Parameters) : null; - Examples = components?.Examples != null ? DictionaryCloneHelper.Clone(components.Examples) : null; - RequestBodies = components?.RequestBodies != null ? DictionaryCloneHelper.Clone(components.RequestBodies) : null; - Headers = components?.Headers != null ? DictionaryCloneHelper.Clone(components.Headers) : null; - SecuritySchemes = components?.SecuritySchemes != null ? DictionaryCloneHelper.Clone(components.SecuritySchemes) : null; - Links = components?.Links != null ? DictionaryCloneHelper.Clone(components.Links) : null; - Callbacks = components?.Callbacks != null ? DictionaryCloneHelper.Clone(components.Callbacks) : null; + 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); Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index f80e976cb..2bf5dd2f2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -89,7 +89,7 @@ public OpenApiDocument(OpenApiDocument document) SecurityRequirements = document?.SecurityRequirements != null ? new List(document.SecurityRequirements) : null; Tags = document?.Tags != null ? new List(document.Tags) : null; ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null; - Extensions = document?.Extensions != null ? DictionaryCloneHelper.Clone(document.Extensions) : null; + Extensions = document?.Extensions != null ? new Dictionary(document.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index d16b6bb56..23a45653a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -65,11 +65,11 @@ public OpenApiEncoding() {} public OpenApiEncoding(OpenApiEncoding encoding) { ContentType = encoding?.ContentType ?? ContentType; - Headers = encoding?.Headers != null ? DictionaryCloneHelper.Clone(encoding.Headers) : null; + Headers = DictionaryCloneHelper.Clone(encoding.Headers); Style = encoding?.Style ?? Style; Explode = encoding?.Explode ?? Explode; AllowReserved = encoding?.AllowReserved ?? AllowReserved; - Extensions = encoding?.Extensions != null ? DictionaryCloneHelper.Clone(encoding.Extensions) : null; + Extensions = DictionaryCloneHelper.Clone(encoding.Extensions); } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 722e1e0d8..73f63a0ab 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -69,7 +69,7 @@ public OpenApiExample(OpenApiExample example) Description = example?.Description ?? Description; Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); ExternalValue = example?.ExternalValue ?? ExternalValue; - Extensions = example?.Extensions != null ? DictionaryCloneHelper.Clone(example.Extensions) : null; + Extensions = DictionaryCloneHelper.Clone(example.Extensions); Reference = example?.Reference != null ? new(example?.Reference) : null; UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 6277a24b7..a2d388a6a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -108,9 +108,9 @@ public OpenApiHeader(OpenApiHeader header) AllowReserved = header?.AllowReserved ?? AllowReserved; Schema = header?.Schema != null ? new(header?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example); - Examples = header?.Examples != null ? DictionaryCloneHelper.Clone(header.Examples) : null; - Content = header?.Content != null ? DictionaryCloneHelper.Clone(header.Content) : null; - Extensions = header?.Extensions != null ? DictionaryCloneHelper.Clone(header.Extensions) : null; + Examples = DictionaryCloneHelper.Clone(header.Examples); + Content = DictionaryCloneHelper.Clone(header.Content); + 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 c141a36f1..06ba9a745 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -56,9 +56,9 @@ public OpenApiMediaType(OpenApiMediaType mediaType) { Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null; Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example); - Examples = mediaType?.Examples != null ? DictionaryCloneHelper.Clone(mediaType.Examples) : null; - Encoding = mediaType?.Encoding != null ? DictionaryCloneHelper.Clone(mediaType.Encoding) : null; - Extensions = mediaType?.Extensions != null ? DictionaryCloneHelper.Clone(mediaType.Extensions) : null; + Examples = DictionaryCloneHelper.Clone(mediaType.Examples); + Encoding = DictionaryCloneHelper.Clone(mediaType.Encoding); + 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 d46dc598e..99438574c 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 = new(operation?.RequestBody); Responses = operation?.Responses != null ? new(operation?.Responses) : null; - Callbacks = operation?.Callbacks != null ? DictionaryCloneHelper.Clone(operation.Callbacks) : null; + Callbacks = DictionaryCloneHelper.Clone(operation.Callbacks); 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 061081752..194a68b3f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -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 = parameter?.Examples != null ? DictionaryCloneHelper.Clone(parameter.Examples) : null; + Examples = DictionaryCloneHelper.Clone(parameter.Examples); Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); - Content = parameter?.Content != null ? DictionaryCloneHelper.Clone(parameter.Content) : null; + Content = DictionaryCloneHelper.Clone(parameter.Content); 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 61de36c7c..a669c67bc 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 = pathItem?.Operations != null ? DictionaryCloneHelper.Clone(pathItem?.Operations) : null; + Operations = DictionaryCloneHelper.Clone(pathItem?.Operations); 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/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 1209c33c7..025422077 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -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 = requestBody?.Content != null ? DictionaryCloneHelper.Clone(requestBody.Content) : null; + Content = DictionaryCloneHelper.Clone(requestBody.Content); 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 2d4a7ac3e..928492da6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -63,10 +63,10 @@ public OpenApiResponse() {} public OpenApiResponse(OpenApiResponse response) { Description = response?.Description ?? Description; - Headers = response?.Headers != null ? DictionaryCloneHelper.Clone(response.Headers) : null; - Content = response?.Content != null ? DictionaryCloneHelper.Clone(response.Content) : null; - Links = response?.Links != null ? DictionaryCloneHelper.Clone(response.Links) : null; - Extensions = response?.Extensions != null ? DictionaryCloneHelper.Clone(response.Extensions) : null; + Headers = DictionaryCloneHelper.Clone(response.Headers); + Content = DictionaryCloneHelper.Clone(response.Content); + Links = DictionaryCloneHelper.Clone(response.Links); + Extensions = response?.Extensions != null ? new Dictionary(response.Extensions) : null; UnresolvedReference = response?.UnresolvedReference ?? UnresolvedReference; Reference = response?.Reference != null ? new(response?.Reference) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index ddb916404..1843c90ff 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 = schema?.Properties != null ? DictionaryCloneHelper.Clone(schema.Properties) : null; + Properties = DictionaryCloneHelper.Clone(schema.Properties); 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 d009e7a14..05dd67ae1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -49,7 +49,7 @@ public OpenApiServer(OpenApiServer server) { Description = server?.Description ?? Description; Url = server?.Url ?? Url; - Variables = server?.Variables != null ? DictionaryCloneHelper.Clone(server.Variables) : null; + Variables = DictionaryCloneHelper.Clone(server.Variables); Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } From 52873821f29f1bf1dc23ce6b50619788bb3a1ccc Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 6 Apr 2023 16:52:01 +0300 Subject: [PATCH 16/21] Update src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs Co-authored-by: Vincent Biret --- src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs index bda087d08..a1976bd70 100644 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -20,7 +20,8 @@ internal class DictionaryCloneHelper /// The cloned dictionary. internal static Dictionary Clone(IDictionary dictionary) { - var clonedDictionary = dictionary is null ? null : new Dictionary(); + if (dictionary is null) return null; + var clonedDictionary = new Dictionary(); if (dictionary != null) { From 90461163140a953dbca6587f022e9cdd9f80384f Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 6 Apr 2023 17:03:09 +0300 Subject: [PATCH 17/21] Add null propagation --- .../Models/OpenApiComponents.cs | 18 +++++++++--------- .../Models/OpenApiEncoding.cs | 4 ++-- src/Microsoft.OpenApi/Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 4 ++-- .../Models/OpenApiMediaType.cs | 4 ++-- .../Models/OpenApiOperation.cs | 2 +- .../Models/OpenApiParameter.cs | 2 +- .../Models/OpenApiRequestBody.cs | 2 +- .../Models/OpenApiResponse.cs | 6 +++--- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 1b1b91abe..9a397b1b0 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 = 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); 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 23a45653a..94c8e5888 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -65,11 +65,11 @@ public OpenApiEncoding() {} public OpenApiEncoding(OpenApiEncoding encoding) { ContentType = encoding?.ContentType ?? ContentType; - Headers = DictionaryCloneHelper.Clone(encoding.Headers); + Headers = DictionaryCloneHelper.Clone(encoding?.Headers); Style = encoding?.Style ?? Style; Explode = encoding?.Explode ?? Explode; AllowReserved = encoding?.AllowReserved ?? AllowReserved; - Extensions = DictionaryCloneHelper.Clone(encoding.Extensions); + Extensions = encoding?.Extensions != null ? new Dictionary(encoding.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 73f63a0ab..b0d15f18a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -69,7 +69,7 @@ public OpenApiExample(OpenApiExample example) Description = example?.Description ?? Description; Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); ExternalValue = example?.ExternalValue ?? ExternalValue; - Extensions = DictionaryCloneHelper.Clone(example.Extensions); + Extensions = example?.Extensions != null ? new Dictionary(example.Extensions) : null; ; Reference = example?.Reference != null ? new(example?.Reference) : null; UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index a2d388a6a..91882aade 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 = DictionaryCloneHelper.Clone(header?.Examples); + Content = DictionaryCloneHelper.Clone(header?.Content); 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 06ba9a745..a8a0497f4 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 = DictionaryCloneHelper.Clone(mediaType?.Examples); + Encoding = DictionaryCloneHelper.Clone(mediaType?.Encoding); 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 99438574c..1491b3aec 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 = new(operation?.RequestBody); Responses = operation?.Responses != null ? new(operation?.Responses) : null; - Callbacks = DictionaryCloneHelper.Clone(operation.Callbacks); + Callbacks = DictionaryCloneHelper.Clone(operation?.Callbacks); 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 194a68b3f..fdeb4d9f6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -163,7 +163,7 @@ 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 = DictionaryCloneHelper.Clone(parameter?.Examples); Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); Content = DictionaryCloneHelper.Clone(parameter.Content); Extensions = parameter?.Extensions != null ? new Dictionary(parameter.Extensions) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 025422077..10603256c 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 = DictionaryCloneHelper.Clone(requestBody?.Content); 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 928492da6..958f20f61 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 = DictionaryCloneHelper.Clone(response?.Headers); + Content = DictionaryCloneHelper.Clone(response?.Content); + Links = DictionaryCloneHelper.Clone(response?.Links); 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/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 05dd67ae1..8f9baed45 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 = DictionaryCloneHelper.Clone(server?.Variables); Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; } From 32d0cd4c2ddd8e0f3fd0f9bdb822ff9ce0215928 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 6 Apr 2023 17:11:56 +0300 Subject: [PATCH 18/21] Push uncommitted code and clean up code --- .../Helpers/DictionaryCloneHelper.cs | 14 ++++++-------- src/Microsoft.OpenApi/Models/OpenApiExample.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 2 +- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs index a1976bd70..279e4639d 100644 --- a/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs @@ -21,16 +21,14 @@ internal class DictionaryCloneHelper internal static Dictionary Clone(IDictionary dictionary) { if (dictionary is null) return null; - var clonedDictionary = new Dictionary(); - - if (dictionary != null) + var clonedDictionary = new Dictionary(dictionary.Keys.Count); + + foreach (var kvp in dictionary) { - foreach (var kvp in dictionary) - { - // Create instance of the specified type using the constructor matching the specified parameter types. - clonedDictionary[kvp.Key] = (U)Activator.CreateInstance(kvp.Value.GetType(), kvp.Value); - } + // Create instance of the specified type using the constructor matching the specified parameter types. + clonedDictionary[kvp.Key] = (U)Activator.CreateInstance(kvp.Value.GetType(), kvp.Value); } + return clonedDictionary; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index b0d15f18a..d8ac064c0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -69,7 +69,7 @@ public OpenApiExample(OpenApiExample example) Description = example?.Description ?? Description; Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value); ExternalValue = example?.ExternalValue ?? ExternalValue; - Extensions = example?.Extensions != null ? new Dictionary(example.Extensions) : null; ; + Extensions = example?.Extensions != null ? new Dictionary(example.Extensions) : null; Reference = example?.Reference != null ? new(example?.Reference) : null; UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index fdeb4d9f6..64dda5445 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -165,7 +165,7 @@ public OpenApiParameter(OpenApiParameter parameter) Schema = parameter?.Schema != null ? new(parameter?.Schema) : null; Examples = DictionaryCloneHelper.Clone(parameter?.Examples); Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(parameter?.Example); - Content = DictionaryCloneHelper.Clone(parameter.Content); + Content = DictionaryCloneHelper.Clone(parameter?.Content); Extensions = parameter?.Extensions != null ? new Dictionary(parameter.Extensions) : null; AllowEmptyValue = parameter?.AllowEmptyValue ?? AllowEmptyValue; Deprecated = parameter?.Deprecated ?? Deprecated; diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 1843c90ff..0b1722bc4 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 = DictionaryCloneHelper.Clone(schema?.Properties); MaxProperties = schema?.MaxProperties ?? MaxProperties; MinProperties = schema?.MinProperties ?? MinProperties; AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed; From 1a9e58cc5b26c6d9863ec12db5775958e44fd726 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 6 Apr 2023 17:24:30 +0300 Subject: [PATCH 19/21] Clean up public API surface --- .../PublicApi/PublicApi.approved.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index df9ef4393..63cd0f535 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -292,14 +292,6 @@ namespace Microsoft.OpenApi.Extensions public static T GetEnumFromDisplayName(this string displayName) { } } } -namespace Microsoft.OpenApi.Helpers -{ - public class DictionaryCloneHelper - { - public DictionaryCloneHelper() { } - public static System.Collections.Generic.Dictionary Clone(System.Collections.Generic.IDictionary dictionary) { } - } -} namespace Microsoft.OpenApi.Interfaces { public interface IEffective From fde82b81db58b778b3eda60e54d2dea404aa3070 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 6 Apr 2023 16:46:29 -0400 Subject: [PATCH 20/21] - makes Path of OpenApiUrlTreeNode Writeable Signed-off-by: Vincent Biret --- src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs | 2 +- test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index e73151943..69597d978 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-preview1 + 1.6.4-preview2 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 86f49db98..c996acbaf 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-preview1 + 1.6.4-preview2 .NET models with JSON and YAML writers for OpenAPI specification © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs index c8e2da03f..9f4ccb8be 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs @@ -26,7 +26,7 @@ public class OpenApiUrlTreeNode /// /// The relative directory path of the current node from the root node. /// - public string Path { get; private set; } = ""; + public string Path { get; set; } = ""; /// /// Dictionary of labels and Path Item objects that describe the operations available on a node. diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 63cd0f535..d993a259e 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1111,7 +1111,7 @@ namespace Microsoft.OpenApi.Services public System.Collections.Generic.IDictionary> AdditionalData { get; set; } public System.Collections.Generic.IDictionary Children { get; } public bool IsParameter { get; } - public string Path { get; } + public string Path { get; set; } public System.Collections.Generic.IDictionary PathItems { get; } public string Segment { get; } public void AddAdditionalData(System.Collections.Generic.Dictionary> additionalData) { } From 2c21e3ef7b97847a4a4f4decdd56ed545c1ade96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:57:09 +0000 Subject: [PATCH 21/21] Bump Verify.Xunit from 19.12.0 to 19.12.1 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 19.12.0 to 19.12.1. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/19.12.0...19.12.1) --- 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 fb7ee1bd6..89c2bacf2 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -28,7 +28,7 @@ - + all