33
44using System ;
55using System . Collections . Generic ;
6+ using System . IO ;
67using System . Linq ;
78using System . Text ;
89using System . Threading . Tasks ;
@@ -16,7 +17,9 @@ namespace Microsoft.OpenApi.Services
1617 /// </summary>
1718 public class OpenApiWorkspace
1819 {
19- private Dictionary < string , OpenApiDocument > _documents = new Dictionary < string , OpenApiDocument > ( ) ;
20+ private Dictionary < Uri , OpenApiDocument > _documents = new Dictionary < Uri , OpenApiDocument > ( ) ;
21+ private Dictionary < Uri , IOpenApiElement > _fragments = new Dictionary < Uri , IOpenApiElement > ( ) ;
22+ private Dictionary < Uri , Stream > _artifacts = new Dictionary < Uri , Stream > ( ) ;
2023
2124 /// <summary>
2225 /// A list of OpenApiDocuments contained in the workspace
@@ -30,44 +33,52 @@ public IEnumerable<OpenApiDocument> Documents {
3033 /// <summary>
3134 /// A list of document fragments that are contained in the workspace
3235 /// </summary>
33- public IEnumerable < IOpenApiFragment > Fragments { get ; }
36+ public IEnumerable < IOpenApiElement > Fragments { get ; }
3437
38+ /// <summary>
39+ /// The base location from where all relative references are resolved
40+ /// </summary>
41+ public Uri BaseUrl { get ; }
42+
43+ /// <summary>
44+ /// A list of document fragments that are contained in the workspace
45+ /// </summary>
46+ public IEnumerable < Stream > Artifacts { get ; }
3547
3648 public bool Contains ( string location )
3749 {
38- return _documents . ContainsKey ( location ) ;
50+ return _documents . ContainsKey ( ToLocationUrl ( location ) ) ;
3951 }
4052
41- public void AddDocument ( string location , OpenApiDocument document )
53+ public void AddDocument ( string location , OpenApiDocument document )
4254 {
4355 document . Workspace = this ;
44- _documents . Add ( location , document ) ;
56+ _documents . Add ( ToLocationUrl ( location ) , document ) ;
4557 }
4658
47- public void AddFragment ( string location , IOpenApiFragment fragment )
59+ public void AddFragment ( string location , IOpenApiElement fragment )
4860 {
49-
61+ _fragments . Add ( ToLocationUrl ( location ) , fragment ) ;
5062 }
5163
52- public void AddArtifact < T > ( string location , T artifact )
64+ public void AddArtifact ( string location , Stream artifact )
5365 {
54-
66+ _artifacts . Add ( ToLocationUrl ( location ) , artifact ) ;
5567 }
5668
5769 public IOpenApiReferenceable ResolveReference ( OpenApiReference reference )
5870 {
59- if ( ! _documents . TryGetValue ( reference . ExternalResource , out var doc ) )
71+ if ( ! _documents . TryGetValue ( new Uri ( reference . ExternalResource , UriKind . RelativeOrAbsolute ) , out var doc ) )
6072 {
6173 return null ;
6274 }
6375
6476 return doc . ResolveReference ( reference , true ) ;
6577 }
6678
67- }
68-
69- public interface IOpenApiFragment
70- {
71- IOpenApiReferenceable ResolveReference ( OpenApiReference reference ) ;
79+ private Uri ToLocationUrl ( string location )
80+ {
81+ return new Uri ( BaseUrl , location ) ;
82+ }
7283 }
7384}
0 commit comments