File tree Expand file tree Collapse file tree
test/Microsoft.OpenApi.Readers.Tests/V31Tests Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments