@@ -97,8 +97,6 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IBaseDo
97
97
/// </summary>
98
98
public OpenApiDocument ( )
99
99
{
100
- // BaseUri = new Uri("http://openapi.net/document/" + Guid.NewGuid());
101
- //_docId = Guid.NewGuid().ToString();
102
100
Workspace = new OpenApiWorkspace ( ) ;
103
101
Workspace . AddDocument ( "/" , this ) ;
104
102
}
@@ -485,6 +483,29 @@ public IOpenApiReferenceable ResolveReference(OpenApiReference reference)
485
483
return ResolveReference ( reference , false ) ;
486
484
}
487
485
486
+ /// <summary>
487
+ /// Resolves JsonSchema refs
488
+ /// </summary>
489
+ /// <param name="referenceUri"></param>
490
+ /// <returns>A JsonSchema ref.</returns>
491
+ public JsonSchema ResolveJsonSchemaReference ( Uri referenceUri )
492
+ {
493
+ if ( referenceUri == null ) return null ;
494
+
495
+ OpenApiReference reference = new OpenApiReference ( )
496
+ {
497
+ ExternalResource = referenceUri . OriginalString ,
498
+ Id = referenceUri . OriginalString . Split ( '/' ) . Last ( ) ,
499
+ Type = ReferenceType . Schema
500
+ } ;
501
+
502
+ JsonSchema resolvedSchema = reference . ExternalResource . StartsWith ( "#" )
503
+ ? ( JsonSchema ) Workspace . ResolveReference < IBaseDocument > ( reference . Id , reference . Type , Components ) // local ref
504
+ : Workspace . ResolveReference < JsonSchema > ( reference ) ; // external ref
505
+
506
+ return resolvedSchema ?? throw new OpenApiException ( string . Format ( Properties . SRResource . InvalidReferenceId , reference . Id ) ) ;
507
+ }
508
+
488
509
/// <summary>
489
510
/// Takes in an OpenApi document instance and generates its hash value
490
511
/// </summary>
@@ -536,7 +557,7 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
536
557
{
537
558
throw new ArgumentException ( Properties . SRResource . WorkspaceRequredForExternalReferenceResolution ) ;
538
559
}
539
- return this . Workspace . ResolveReference ( reference ) ;
560
+ return this . Workspace . ResolveReference < IOpenApiReferenceable > ( reference ) ;
540
561
}
541
562
542
563
if ( ! reference . Type . HasValue )
@@ -559,16 +580,8 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
559
580
return null ;
560
581
}
561
582
562
- IOpenApiReferenceable resolvedReference = Workspace . ResolveReference < IOpenApiReferenceable > ( reference . Id , reference . Type , Components ) ;
563
-
564
- if ( resolvedReference != null )
565
- {
566
- return resolvedReference ;
567
- }
568
- else
569
- {
570
- throw new OpenApiException ( string . Format ( Properties . SRResource . InvalidReferenceId , reference . Id ) ) ;
571
- }
583
+ return Workspace . ResolveReference < IOpenApiReferenceable > ( reference . Id , reference . Type , Components )
584
+ ?? throw new OpenApiException ( string . Format ( Properties . SRResource . InvalidReferenceId , reference . Id ) ) ;
572
585
}
573
586
574
587
/// <summary>
0 commit comments