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(
71
71
string reference ,
72
72
ReferenceType ? type )
73
73
{
74
+ var openApiReference = new OpenApiReference ( ) ;
74
75
if ( ! string . IsNullOrWhiteSpace ( reference ) )
75
76
{
76
77
var segments = reference . Split ( '#' ) ;
@@ -127,13 +128,16 @@ public OpenApiReference ConvertToOpenApiReference(
127
128
}
128
129
id = localSegments [ 3 ] ;
129
130
}
130
-
131
- return new OpenApiReference
131
+ else
132
132
{
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 ;
137
141
}
138
142
}
139
143
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ public class OpenApiReference : IOpenApiSerializable
45
45
/// </summary>
46
46
public bool IsLocal => ExternalResource == null ;
47
47
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
+
48
53
/// <summary>
49
54
/// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference.
50
55
/// </summary>
@@ -196,7 +201,12 @@ private string GetExternalReferenceV3()
196
201
{
197
202
if ( Id != null )
198
203
{
199
- return ExternalResource + "#/components/" + Type . GetDisplayName ( ) + "/" + Id ;
204
+ if ( IsFragrament )
205
+ {
206
+ return ExternalResource + "#" + Id ;
207
+ }
208
+
209
+ return ExternalResource + "#/components/" + Type . GetDisplayName ( ) + "/" + Id ;
200
210
}
201
211
202
212
return ExternalResource ;
You can’t perform that action at this time.
0 commit comments