1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
- using System ;
5
4
using System . IO ;
6
5
using System . Text . Json . Nodes ;
7
6
using System . Text . Json ;
12
11
using Microsoft . OpenApi . Extensions ;
13
12
using Microsoft . OpenApi . Validations ;
14
13
using System . Linq ;
15
- using System . Collections . Generic ;
16
14
using Microsoft . OpenApi . Services ;
17
15
using Microsoft . OpenApi . Interfaces ;
18
16
using Microsoft . OpenApi . Reader . Services ;
@@ -95,7 +93,7 @@ public async Task<ReadResult> ReadAsync(JsonNode jsonNode,
95
93
}
96
94
}
97
95
98
- ResolveReferences ( diagnostic , document , settings ) ;
96
+ SetHostDocument ( document ) ;
99
97
}
100
98
catch ( OpenApiException ex )
101
99
{
@@ -189,28 +187,6 @@ private JsonNode LoadJsonNodes(TextReader input)
189
187
return nodes ;
190
188
}
191
189
192
- private void ResolveReferences ( OpenApiDiagnostic diagnostic , OpenApiDocument document , OpenApiReaderSettings settings )
193
- {
194
- List < OpenApiError > errors = new ( ) ;
195
-
196
- // Resolve References if requested
197
- switch ( settings . ReferenceResolution )
198
- {
199
- case ReferenceResolutionSetting . ResolveAllReferences :
200
- throw new ArgumentException ( "Resolving external references is not supported" ) ;
201
- case ReferenceResolutionSetting . ResolveLocalReferences :
202
- errors . AddRange ( document . ResolveReferences ( ) ) ;
203
- break ;
204
- case ReferenceResolutionSetting . DoNotResolveReferences :
205
- break ;
206
- }
207
-
208
- foreach ( var item in errors )
209
- {
210
- diagnostic . Errors . Add ( item ) ;
211
- }
212
- }
213
-
214
190
private async Task < OpenApiDiagnostic > LoadExternalRefs ( OpenApiDocument document , CancellationToken cancellationToken , OpenApiReaderSettings settings , string format = null )
215
191
{
216
192
// Create workspace for all documents to live in.
@@ -221,5 +197,10 @@ private async Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document,
221
197
var workspaceLoader = new OpenApiWorkspaceLoader ( openApiWorkSpace , settings . CustomExternalLoader ?? streamLoader , settings ) ;
222
198
return await workspaceLoader . LoadAsync ( new OpenApiReference ( ) { ExternalResource = "/" } , document , format ?? OpenApiConstants . Json , null , cancellationToken ) ;
223
199
}
200
+
201
+ private void SetHostDocument ( OpenApiDocument document )
202
+ {
203
+ document . SetHostDocument ( ) ;
204
+ }
224
205
}
225
206
}
0 commit comments