@@ -223,7 +223,7 @@ public void ResolveSubSchema_ShouldTraverseKnownKeywords()
223223
224224 var path = new [ ] { "properties" , "a" , "properties" , "b" } ;
225225
226- var result = OpenApiWorkspace . ResolveSubSchema ( schema , path ) ;
226+ var result = OpenApiWorkspace . ResolveSubSchema ( schema , path , [ ] ) ;
227227
228228 Assert . NotNull ( result ) ;
229229 Assert . Equal ( JsonSchemaType . String , result ! . Type ) ;
@@ -250,7 +250,7 @@ public void ResolveSubSchema_ShouldHandleUserDefinedKeywordNamedProperty(string[
250250 }
251251 } ;
252252
253- var result = OpenApiWorkspace . ResolveSubSchema ( schema , pathSegments ) ;
253+ var result = OpenApiWorkspace . ResolveSubSchema ( schema , pathSegments , [ ] ) ;
254254
255255 Assert . NotNull ( result ) ;
256256 Assert . Equal ( JsonSchemaType . String , result ! . Type ) ;
@@ -275,7 +275,7 @@ public void ResolveSubSchema_ShouldRecurseIntoAllOfComposition()
275275
276276 var path = new [ ] { "allOf" , "0" , "properties" , "x" } ;
277277
278- var result = OpenApiWorkspace . ResolveSubSchema ( schema , path ) ;
278+ var result = OpenApiWorkspace . ResolveSubSchema ( schema , path , [ ] ) ;
279279
280280 Assert . NotNull ( result ) ;
281281 Assert . Equal ( JsonSchemaType . Integer , result ! . Type ) ;
@@ -434,6 +434,81 @@ public async Task ShouldResolveReferencesInSchemasFromSystemTextJson()
434434 var updatedTagsProperty = Assert . IsType < OpenApiSchemaReference > ( schema . Properties [ "tags" ] ) ;
435435 Assert . Equal ( absoluteReferenceId , updatedTagsProperty . Reference . ReferenceV3 ) ;
436436 Assert . Equal ( JsonSchemaType . Array | JsonSchemaType . Null , updatedTagsProperty . Type ) ;
437+ Assert . Equal ( JsonSchemaType . Object , updatedTagsProperty . Items . Type ) ;
438+
439+
440+ // doing the same for the parent property
441+
442+ var parentProperty = Assert . IsType < OpenApiSchema > ( schema . Properties [ "parent" ] ) ;
443+ var parentSubProperty = Assert . IsType < OpenApiSchemaReference > ( parentProperty . Properties [ "parent" ] ) ;
444+ Assert . Equal ( "#/properties/parent" , parentSubProperty . Reference . ReferenceV3 ) ;
445+ parentProperty . Properties [ "parent" ] = new OpenApiSchemaReference ( $ "#/components/schemas/Foo{ parentSubProperty . Reference . ReferenceV3 . Replace ( "#" , string . Empty ) } ", document ) ;
446+ var updatedParentSubProperty = Assert . IsType < OpenApiSchemaReference > ( parentProperty . Properties [ "parent" ] ) ;
447+ Assert . Equal ( JsonSchemaType . Object | JsonSchemaType . Null , updatedParentSubProperty . Type ) ;
448+
449+ var pathItem = new OpenApiPathItem
450+ {
451+ Operations = new Dictionary < HttpMethod , OpenApiOperation >
452+ {
453+ [ HttpMethod . Post ] = new OpenApiOperation
454+ {
455+ Responses = new OpenApiResponses
456+ {
457+ [ "200" ] = new OpenApiResponse
458+ {
459+ }
460+ } ,
461+ RequestBody = new OpenApiRequestBody
462+ {
463+ Content = new Dictionary < string , OpenApiMediaType >
464+ {
465+ [ "application/json" ] = new OpenApiMediaType
466+ {
467+ Schema = new OpenApiSchemaReference ( "#/components/schemas/Foo" , document )
468+ }
469+ }
470+ }
471+ }
472+ }
473+ } ;
474+ document . Paths . Add ( "/" , pathItem ) ;
475+
476+ var requestBodySchema = pathItem . Operations [ HttpMethod . Post ] . RequestBody . Content [ "application/json" ] . Schema ;
477+ Assert . NotNull ( requestBodySchema ) ;
478+ var requestBodyTagsProperty = Assert . IsType < OpenApiSchemaReference > ( requestBodySchema . Properties [ "tags" ] ) ;
479+ Assert . Equal ( JsonSchemaType . Object , requestBodyTagsProperty . Items . Type ) ;
480+ }
481+
482+ [ Fact ]
483+ public void ExitsEarlyOnCyclicalReferences ( )
484+ {
485+ var document = new OpenApiDocument
486+ {
487+ Info = new OpenApiInfo { Title = "Test API" , Version = "1.0.0" } ,
488+ } ;
489+ var categorySchema = new OpenApiSchema
490+ {
491+ Type = JsonSchemaType . Object ,
492+ Properties = new Dictionary < string , IOpenApiSchema >
493+ {
494+ [ "name" ] = new OpenApiSchema { Type = JsonSchemaType . String } ,
495+ [ "parent" ] = new OpenApiSchemaReference ( "#/components/schemas/Category" , document ) ,
496+ // this is intentionally wrong and cyclical reference
497+ // it tests whether we're going in an infinite resolution loop
498+ [ "tags" ] = new OpenApiSchemaReference ( "#/components/schemas/Category/properties/parent/properties/tags" , document )
499+ }
500+ } ;
501+ document . AddComponent ( "Category" , categorySchema ) ;
502+ document . RegisterComponents ( ) ;
503+
504+ var tagsSchemaRef = Assert . IsType < OpenApiSchemaReference > ( categorySchema . Properties [ "tags" ] ) ;
505+ Assert . Null ( tagsSchemaRef . Items ) ;
506+ Assert . Equal ( "#/components/schemas/Category/properties/parent/properties/tags" , tagsSchemaRef . Reference . ReferenceV3 ) ;
507+ Assert . Null ( tagsSchemaRef . Target ) ;
508+
509+ var parentSchemaRef = Assert . IsType < OpenApiSchemaReference > ( categorySchema . Properties [ "parent" ] ) ;
510+ Assert . Equal ( "#/components/schemas/Category" , parentSchemaRef . Reference . ReferenceV3 ) ;
511+ Assert . NotNull ( parentSchemaRef . Target ) ;
437512 }
438513 }
439514}
0 commit comments