File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
Microsoft.OpenApi.Readers/V3 Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ public OpenApiReference ConvertToOpenApiReference(
7171 string reference ,
7272 ReferenceType ? type )
7373 {
74+ var openApiReference = new OpenApiReference ( ) ;
7475 if ( ! string . IsNullOrWhiteSpace ( reference ) )
7576 {
7677 var segments = reference . Split ( '#' ) ;
@@ -127,13 +128,16 @@ public OpenApiReference ConvertToOpenApiReference(
127128 }
128129 id = localSegments [ 3 ] ;
129130 }
130-
131- return new OpenApiReference
131+ else
132132 {
133- ExternalResource = segments [ 0 ] ,
134- Type = type ,
135- Id = id
136- } ;
133+ openApiReference . IsFragrament = true ;
134+ }
135+
136+ openApiReference . ExternalResource = segments [ 0 ] ;
137+ openApiReference . Type = type ;
138+ openApiReference . Id = id ;
139+
140+ return openApiReference ;
137141 }
138142 }
139143
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ public class OpenApiReference : IOpenApiSerializable
4545 /// </summary>
4646 public bool IsLocal => ExternalResource == null ;
4747
48+ /// <summary>
49+ /// Gets a flag indicating whether a file is a valid OpenAPI document or a fragment
50+ /// </summary>
51+ public bool IsFragrament = false ;
52+
4853 /// <summary>
4954 /// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference.
5055 /// </summary>
@@ -196,7 +201,12 @@ private string GetExternalReferenceV3()
196201 {
197202 if ( Id != null )
198203 {
199- return ExternalResource + "#/components/" + Type . GetDisplayName ( ) + "/" + Id ;
204+ if ( IsFragrament )
205+ {
206+ return ExternalResource + "#" + Id ;
207+ }
208+
209+ return ExternalResource + "#/components/" + Type . GetDisplayName ( ) + "/" + Id ;
200210 }
201211
202212 return ExternalResource ;
You can’t perform that action at this time.
0 commit comments