File tree Expand file tree Collapse file tree
test/Microsoft.OpenApi.Readers.Tests/V3Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -418,6 +418,78 @@ public void ParseBasicSchemaWithReferenceShouldSucceed()
418418 } , options => options . Excluding ( m => m . Name == "HostDocument" ) ) ;
419419 }
420420
421+ [ Fact ]
422+ public void ParseSchemaWithCircularPropertyReferencesShouldSucceed ( )
423+ {
424+ var openApiDoc = new OpenApiStringReader ( ) . Read ( """
425+ {
426+ "openapi": "3.0.0",
427+ "info": {
428+ "title": "Test",
429+ "version": "0.0.1"
430+ },
431+ "paths": {},
432+ "components": {
433+ "schemas": {
434+ "A": {
435+ "properties": {
436+ "b": {
437+ "$ref": "#/components/schemas/B"
438+ }
439+ }
440+ },
441+ "B": {
442+ "properties": {
443+ "a": {
444+ "$ref": "#/components/schemas/A"
445+ }
446+ }
447+ }
448+ }
449+ }
450+ }
451+ """ , out var diagnostic ) ;
452+
453+ diagnostic . Should ( ) . BeEquivalentTo (
454+ new OpenApiDiagnostic { SpecificationVersion = OpenApiSpecVersion . OpenApi3_0 } ) ;
455+
456+ var schemaA = openApiDoc . Components . Schemas [ "A" ] ;
457+ var schemaB = openApiDoc . Components . Schemas [ "B" ] ;
458+
459+ schemaA . Properties [ "b" ] . Should ( ) . BeSameAs ( schemaB ) ;
460+ schemaB . Properties [ "a" ] . Should ( ) . BeSameAs ( schemaA ) ;
461+ }
462+
463+ [ Fact ]
464+ public void ParseSchemaWithCircularRootReferencesShouldSucceed ( )
465+ {
466+ var openApiDoc = new OpenApiStringReader ( ) . Read ( """
467+ {
468+ "openapi": "3.0.0",
469+ "info": {
470+ "title": "Test",
471+ "version": "0.0.1"
472+ },
473+ "paths": {},
474+ "components": {
475+ "schemas": {
476+ "A": {
477+ "$ref": "#/components/schemas/B"
478+ },
479+ "B": {
480+ "$ref": "#/components/schemas/A"
481+ }
482+ }
483+ }
484+ }
485+ """ , out var diagnostic ) ;
486+
487+ diagnostic . Should ( ) . BeEquivalentTo (
488+ new OpenApiDiagnostic { SpecificationVersion = OpenApiSpecVersion . OpenApi3_0 } ) ;
489+
490+ openApiDoc . Components . Schemas [ "A" ] . Should ( ) . BeSameAs ( openApiDoc . Components . Schemas [ "B" ] ) ;
491+ }
492+
421493 [ Fact ]
422494 public void ParseAdvancedSchemaWithReferenceShouldSucceed ( )
423495 {
You can’t perform that action at this time.
0 commit comments