@@ -49,7 +49,7 @@ public class MainModel : INotifyPropertyChanged
49
49
/// </summary>
50
50
private OpenApiSpecVersion _version = OpenApiSpecVersion . OpenApi3_0 ;
51
51
52
- private HttpClient _httpClient = new ( ) ;
52
+ private static readonly HttpClient _httpClient = new ( ) ;
53
53
54
54
public string Input
55
55
{
@@ -166,31 +166,31 @@ public OpenApiSpecVersion Version
166
166
public bool IsYaml
167
167
{
168
168
get => Format == OpenApiFormat . Yaml ;
169
- set => Format = OpenApiFormat . Yaml ;
169
+ set => Format = value ? OpenApiFormat . Yaml : Format ;
170
170
}
171
171
172
172
public bool IsJson
173
173
{
174
174
get => Format == OpenApiFormat . Json ;
175
- set => Format = OpenApiFormat . Json ;
175
+ set => Format = value ? OpenApiFormat . Json : Format ;
176
176
}
177
177
178
178
public bool IsV2_0
179
179
{
180
180
get => Version == OpenApiSpecVersion . OpenApi2_0 ;
181
- set => Version = OpenApiSpecVersion . OpenApi2_0 ;
181
+ set => Version = value ? OpenApiSpecVersion . OpenApi2_0 : Version ;
182
182
}
183
183
184
184
public bool IsV3_0
185
185
{
186
186
get => Version == OpenApiSpecVersion . OpenApi3_0 ;
187
- set => Version = OpenApiSpecVersion . OpenApi3_0 ;
187
+ set => Version = value ? OpenApiSpecVersion . OpenApi3_0 : Version ;
188
188
}
189
189
190
190
public bool IsV3_1
191
191
{
192
192
get => Version == OpenApiSpecVersion . OpenApi3_1 ;
193
- set => Version = OpenApiSpecVersion . OpenApi3_1 ;
193
+ set => Version = value ? OpenApiSpecVersion . OpenApi3_1 : Version ;
194
194
}
195
195
196
196
/// <summary>
@@ -219,14 +219,8 @@ internal async Task ParseDocumentAsync()
219
219
{
220
220
if ( ! string . IsNullOrWhiteSpace ( _inputFile ) )
221
221
{
222
- if ( _inputFile . StartsWith ( "http" ) )
223
- {
224
- stream = await _httpClient . GetStreamAsync ( _inputFile ) ;
225
- }
226
- else
227
- {
228
- stream = new FileStream ( _inputFile , FileMode . Open ) ;
229
- }
222
+ stream = _inputFile . StartsWith ( "http" ) ? await _httpClient . GetStreamAsync ( _inputFile )
223
+ : new FileStream ( _inputFile , FileMode . Open ) ;
230
224
}
231
225
else
232
226
{
@@ -245,20 +239,13 @@ internal async Task ParseDocumentAsync()
245
239
ReferenceResolution = ResolveExternal ? ReferenceResolutionSetting . ResolveAllReferences : ReferenceResolutionSetting . ResolveLocalReferences ,
246
240
RuleSet = ValidationRuleSet . GetDefaultRuleSet ( )
247
241
} ;
248
- if ( ResolveExternal )
242
+ if ( ResolveExternal && ! string . IsNullOrWhiteSpace ( _inputFile ) )
249
243
{
250
- if ( _inputFile . StartsWith ( "http" ) )
251
- {
252
- settings . BaseUrl = new ( _inputFile ) ;
253
- }
254
- else
255
- {
256
- settings . BaseUrl = new ( "file://" + Path . GetDirectoryName ( _inputFile ) + "/" ) ;
257
- }
244
+ settings . BaseUrl = _inputFile . StartsWith ( "http" ) ? new ( _inputFile )
245
+ : new ( "file://" + Path . GetDirectoryName ( _inputFile ) + "/" ) ;
258
246
}
259
247
260
- var format = OpenApiModelFactory . GetFormat ( _inputFile ) ;
261
- var readResult = await OpenApiDocument . LoadAsync ( stream , format ) ;
248
+ var readResult = await OpenApiDocument . LoadAsync ( stream , Format . GetDisplayName ( ) ) ;
262
249
var document = readResult . OpenApiDocument ;
263
250
var context = readResult . OpenApiDiagnostic ;
264
251
@@ -306,7 +293,6 @@ internal async Task ParseDocumentAsync()
306
293
stream . Close ( ) ;
307
294
await stream . DisposeAsync ( ) ;
308
295
}
309
-
310
296
}
311
297
}
312
298
@@ -332,7 +318,7 @@ private string WriteContents(OpenApiDocument document)
332
318
return new StreamReader ( outputStream ) . ReadToEnd ( ) ;
333
319
}
334
320
335
- private MemoryStream CreateStream ( string text )
321
+ private static MemoryStream CreateStream ( string text )
336
322
{
337
323
var stream = new MemoryStream ( ) ;
338
324
var writer = new StreamWriter ( stream ) ;
0 commit comments