Skip to content

Commit af0686a

Browse files
committed
test: add CreateShallowCopy test to cover JsonSchemaReference copy constructor
Achieves 100% diff coverage on all changed files. Ref: #2895
1 parent fcf4dbf commit af0686a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,5 +1305,42 @@ public async Task SerializeSchemaReferencePreservesVocabularySibling()
13051305
referencing.Vocabulary["https://json-schema.org/draft/2020-12/vocab/core"].Should().BeTrue();
13061306
referencing.Vocabulary["https://json-schema.org/draft/2020-12/vocab/applicator"].Should().BeFalse();
13071307
}
1308+
1309+
[Fact]
1310+
public async Task CreateShallowCopyPreservesKeywordSiblings()
1311+
{
1312+
// Arrange
1313+
var yaml = """
1314+
openapi: 3.1.0
1315+
info:
1316+
title: Shallow copy repro
1317+
version: 1.0.0
1318+
paths: {}
1319+
components:
1320+
schemas:
1321+
Target:
1322+
type: object
1323+
Referencing:
1324+
$ref: '#/components/schemas/Target'
1325+
$dynamicAnchor: anchor
1326+
$defs:
1327+
sibling:
1328+
$dynamicAnchor: inner
1329+
$ref: '#/components/schemas/Target'
1330+
""";
1331+
1332+
// Act
1333+
using var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(yaml));
1334+
var result = await OpenApiDocument.LoadAsync(stream, "yaml", SettingsFixture.ReaderSettings);
1335+
var referencing = result.Document.Components!.Schemas["Referencing"];
1336+
var copy = referencing.CreateShallowCopy();
1337+
1338+
// Assert — CreateShallowCopy preserves sibling values via the JsonSchemaReference copy constructor
1339+
copy.Should().BeOfType<OpenApiSchemaReference>();
1340+
copy.DynamicAnchor.Should().Be("anchor");
1341+
copy.Definitions.Should().NotBeNull();
1342+
copy.Definitions!.Should().ContainKey("sibling");
1343+
copy.Definitions["sibling"].DynamicAnchor.Should().Be("inner");
1344+
}
13081345
}
13091346
}

0 commit comments

Comments
 (0)