@@ -49,7 +49,7 @@ public class MainModel : INotifyPropertyChanged
4949 /// </summary>
5050 private OpenApiSpecVersion _version = OpenApiSpecVersion . OpenApi3_0 ;
5151
52- private HttpClient _httpClient = new ( ) ;
52+ private static readonly HttpClient _httpClient = new ( ) ;
5353
5454 public string Input
5555 {
@@ -166,31 +166,31 @@ public OpenApiSpecVersion Version
166166 public bool IsYaml
167167 {
168168 get => Format == OpenApiFormat . Yaml ;
169- set => Format = OpenApiFormat . Yaml ;
169+ set => Format = value ? OpenApiFormat . Yaml : Format ;
170170 }
171171
172172 public bool IsJson
173173 {
174174 get => Format == OpenApiFormat . Json ;
175- set => Format = OpenApiFormat . Json ;
175+ set => Format = value ? OpenApiFormat . Json : Format ;
176176 }
177177
178178 public bool IsV2_0
179179 {
180180 get => Version == OpenApiSpecVersion . OpenApi2_0 ;
181- set => Version = OpenApiSpecVersion . OpenApi2_0 ;
181+ set => Version = value ? OpenApiSpecVersion . OpenApi2_0 : Version ;
182182 }
183183
184184 public bool IsV3_0
185185 {
186186 get => Version == OpenApiSpecVersion . OpenApi3_0 ;
187- set => Version = OpenApiSpecVersion . OpenApi3_0 ;
187+ set => Version = value ? OpenApiSpecVersion . OpenApi3_0 : Version ;
188188 }
189189
190190 public bool IsV3_1
191191 {
192192 get => Version == OpenApiSpecVersion . OpenApi3_1 ;
193- set => Version = OpenApiSpecVersion . OpenApi3_1 ;
193+ set => Version = value ? OpenApiSpecVersion . OpenApi3_1 : Version ;
194194 }
195195
196196 /// <summary>
@@ -219,14 +219,8 @@ internal async Task ParseDocumentAsync()
219219 {
220220 if ( ! string . IsNullOrWhiteSpace ( _inputFile ) )
221221 {
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 ) ;
230224 }
231225 else
232226 {
@@ -245,20 +239,13 @@ internal async Task ParseDocumentAsync()
245239 ReferenceResolution = ResolveExternal ? ReferenceResolutionSetting . ResolveAllReferences : ReferenceResolutionSetting . ResolveLocalReferences ,
246240 RuleSet = ValidationRuleSet . GetDefaultRuleSet ( )
247241 } ;
248- if ( ResolveExternal )
242+ if ( ResolveExternal && ! string . IsNullOrWhiteSpace ( _inputFile ) )
249243 {
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 ) + "/" ) ;
258246 }
259247
260- var format = OpenApiModelFactory . GetFormat ( _inputFile ) ;
261- var readResult = await OpenApiDocument . LoadAsync ( stream , format ) ;
248+ var readResult = await OpenApiDocument . LoadAsync ( stream , Format . GetDisplayName ( ) ) ;
262249 var document = readResult . OpenApiDocument ;
263250 var context = readResult . OpenApiDiagnostic ;
264251
@@ -306,7 +293,6 @@ internal async Task ParseDocumentAsync()
306293 stream . Close ( ) ;
307294 await stream . DisposeAsync ( ) ;
308295 }
309-
310296 }
311297 }
312298
@@ -332,7 +318,7 @@ private string WriteContents(OpenApiDocument document)
332318 return new StreamReader ( outputStream ) . ReadToEnd ( ) ;
333319 }
334320
335- private MemoryStream CreateStream ( string text )
321+ private static MemoryStream CreateStream ( string text )
336322 {
337323 var stream = new MemoryStream ( ) ;
338324 var writer = new StreamWriter ( stream ) ;
0 commit comments