diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 0176ea1d9..b0ac2dbac 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -288,6 +288,7 @@ public OpenApiSchema(OpenApiSchema schema) ExternalDocs = schema?.ExternalDocs != null ? new(schema?.ExternalDocs) : null; Deprecated = schema?.Deprecated ?? Deprecated; Xml = schema?.Xml != null ? new(schema?.Xml) : null; + Extensions = schema?.Extensions != null ? new Dictionary(schema.Extensions) : null; UnresolvedReference = schema?.UnresolvedReference ?? UnresolvedReference; Reference = schema?.Reference != null ? new(schema?.Reference) : null; } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index e4078f2f7..2a0dd0039 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -9,6 +9,7 @@ using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Writers; using VerifyXunit; @@ -479,5 +480,29 @@ public void OpenApiSchemaCopyConstructorSucceeds() Assert.Equal("date", actualSchema.Format); Assert.True(actualSchema.Nullable); } + + [Fact] + public void CloningSchemaExtensionsWorks() + { + // Arrange + var schema = new OpenApiSchema + { + Extensions = + { + { "x-myextension", new OpenApiInteger(42) } + } + }; + + // Act && Assert + var schemaCopy = new OpenApiSchema(schema); + Assert.Equal(1, schemaCopy.Extensions.Count); + + // Act && Assert + schemaCopy.Extensions = new Dictionary + { + { "x-myextension" , new OpenApiInteger(40) } + }; + Assert.NotEqual(schema.Extensions, schemaCopy.Extensions); + } } } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index d993a259e..96071507f 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1024,6 +1024,8 @@ namespace Microsoft.OpenApi.Models Callback = 8, [Microsoft.OpenApi.Attributes.Display("tags")] Tag = 9, + [Microsoft.OpenApi.Attributes.Display("paths")] + Path = 10, } public class RuntimeExpressionAnyWrapper : Microsoft.OpenApi.Interfaces.IOpenApiElement {