Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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);
}
}
}