Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, IOpenApiExtension>(schema.Extensions) : null;
UnresolvedReference = schema?.UnresolvedReference ?? UnresolvedReference;
Reference = schema?.Reference != null ? new(schema?.Reference) : null;
}
Expand Down
25 changes: 25 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, IOpenApiExtension>
{
{ "x-myextension" , new OpenApiInteger(40) }
};
Assert.NotEqual(schema.Extensions, schemaCopy.Extensions);
}
}
}
2 changes: 2 additions & 0 deletions test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down