@@ -312,7 +312,7 @@ public async Task ShouldResolveRelativeSubReferenceUsingParsingContext()
312312 parsingContext . StartObject ( "schemas" ) ;
313313 parsingContext . StartObject ( "Foo" ) ;
314314 var document = new OpenApiDocument ( ) ;
315-
315+
316316 // Act
317317 var fooComponentSchema = parsingContext . ParseFragment < OpenApiSchema > ( schemaJsonNode , OpenApiSpecVersion . OpenApi3_1 , document ) ;
318318 document . AddComponent ( "Foo" , fooComponentSchema ) ;
@@ -412,5 +412,28 @@ public async Task ShouldResolveRecursiveRelativeSubReference()
412412 Assert . Equal ( JsonSchemaType . Array | JsonSchemaType . Null , fooSchemaTagsProperty . Type ) ;
413413 Assert . Equal ( JsonSchemaType . Object , fooSchemaTagsProperty . Items . Type ) ;
414414 }
415+ [ Fact ]
416+ public async Task ShouldResolveReferencesInSchemasFromSystemTextJson ( )
417+ {
418+ var filePath = Path . Combine ( SampleFolderPath , "STJSchema.json" ) ;
419+ using var fs = File . OpenRead ( filePath ) ;
420+ var jsonNode = await JsonNode . ParseAsync ( fs ) ;
421+
422+ var parsingContext = new ParsingContext ( new OpenApiDiagnostic ( ) ) ;
423+ var document = new OpenApiDocument ( ) ;
424+ var schema = parsingContext . ParseFragment < OpenApiSchema > ( jsonNode , OpenApiSpecVersion . OpenApi3_1 , document ) ;
425+ Assert . NotNull ( schema ) ;
426+
427+ document . AddComponent ( "Foo" , schema ) ;
428+ var tagsProperty = Assert . IsType < OpenApiSchemaReference > ( schema . Properties [ "tags" ] ) ;
429+ // this is the reference that is generated by STJ schema generator which does not have OAI in context.
430+ Assert . Equal ( "#/properties/parent/properties/tags" , tagsProperty . Reference . ReferenceV3 ) ;
431+ // this is the reference that needs to be used in the document for components resolution.
432+ var absoluteReferenceId = $ "#/components/schemas/Foo{ tagsProperty . Reference . ReferenceV3 . Replace ( "#" , string . Empty ) } ";
433+ schema . Properties [ "tags" ] = new OpenApiSchemaReference ( absoluteReferenceId , document ) ;
434+ var updatedTagsProperty = Assert . IsType < OpenApiSchemaReference > ( schema . Properties [ "tags" ] ) ;
435+ Assert . Equal ( absoluteReferenceId , updatedTagsProperty . Reference . ReferenceV3 ) ;
436+ Assert . Equal ( JsonSchemaType . Array | JsonSchemaType . Null , updatedTagsProperty . Type ) ;
437+ }
415438 }
416439}
0 commit comments