7
7
using System . Linq ;
8
8
using System . Text ;
9
9
using System . Threading . Tasks ;
10
+ using Microsoft . OpenApi . Extensions ;
10
11
using Microsoft . OpenApi . Interfaces ;
11
12
using Microsoft . OpenApi . Models ;
12
13
@@ -18,7 +19,7 @@ namespace Microsoft.OpenApi.Services
18
19
public class OpenApiWorkspace
19
20
{
20
21
private Dictionary < Uri , OpenApiDocument > _documents = new Dictionary < Uri , OpenApiDocument > ( ) ;
21
- private Dictionary < Uri , IOpenApiElement > _fragments = new Dictionary < Uri , IOpenApiElement > ( ) ;
22
+ private Dictionary < Uri , IOpenApiReferenceable > _fragments = new Dictionary < Uri , IOpenApiReferenceable > ( ) ;
22
23
private Dictionary < Uri , Stream > _artifacts = new Dictionary < Uri , Stream > ( ) ;
23
24
24
25
/// <summary>
@@ -92,7 +93,7 @@ public void AddDocument(string location, OpenApiDocument document)
92
93
/// <remarks>Not sure how this is going to work. Does the reference just point to the fragment as a whole, or do we need to
93
94
/// to be able to point into the fragment. Keeping it private until we figure it out.
94
95
/// </remarks>
95
- private void AddFragment ( string location , IOpenApiElement fragment )
96
+ public void AddFragment ( string location , IOpenApiReferenceable fragment )
96
97
{
97
98
_fragments . Add ( ToLocationUrl ( location ) , fragment ) ;
98
99
}
@@ -114,21 +115,14 @@ public void AddArtifact(string location, Stream artifact)
114
115
/// <returns></returns>
115
116
public IOpenApiReferenceable ResolveReference ( OpenApiReference reference )
116
117
{
117
- if ( _documents . TryGetValue ( new Uri ( BaseUrl , reference . ExternalResource ) , out var doc ) )
118
+ if ( _documents . TryGetValue ( new Uri ( BaseUrl , reference . ExternalResource ) , out var doc ) )
118
119
{
119
- return doc . ResolveReference ( reference , true ) ;
120
+ return doc . ResolveReference ( reference , true ) ;
120
121
}
121
122
else if ( _fragments . TryGetValue ( new Uri ( BaseUrl , reference . ExternalResource ) , out var fragment ) )
122
123
{
123
- var frag = fragment as IOpenApiReferenceable ;
124
- if ( frag != null )
125
- {
126
- return null ; // frag.ResolveReference(reference, true); // IOpenApiElement needs to implement ResolveReference
127
- }
128
- else
129
- {
130
- return null ;
131
- }
124
+ var jsonPointer = $ "/{ reference . Id ?? string . Empty } ";
125
+ return fragment . ResolveReference ( jsonPointer ) ;
132
126
}
133
127
return null ;
134
128
}
0 commit comments