@@ -67,7 +67,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
6767
6868#pragma warning restore CA1308 // Normalize strings to uppercase
6969 options . Output = new ( $ "./output{ inputExtension } ") ;
70- } ;
70+ }
7171
7272 if ( options . CleanOutput && options . Output . Exists )
7373 {
@@ -98,8 +98,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9898 }
9999
100100 // Load OpenAPI document
101- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
102- var document = await GetOpenApiAsync ( options , format , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
101+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
103102
104103 if ( options . FilterOptions != null )
105104 {
@@ -255,7 +254,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
255254 else if ( ! string . IsNullOrEmpty ( options . OpenApi ) )
256255 {
257256 stream = await GetStreamAsync ( options . OpenApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
258- var result = await ParseOpenApiAsync ( options . OpenApi , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
257+ var result = await ParseOpenApiAsync ( options . OpenApi , format , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
259258 document = result . Document ;
260259 }
261260 else throw new InvalidOperationException ( "No input file path or URL provided" ) ;
@@ -352,8 +351,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
352351 try
353352 {
354353 using var stream = await GetStreamAsync ( openApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
355-
356- result = await ParseOpenApiAsync ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
354+ var openApiFormat = ! string . IsNullOrEmpty ( openApi ) ? GetOpenApiFormat ( openApi , logger ) : OpenApiFormat . Yaml ;
355+ result = await ParseOpenApiAsync ( openApi , openApiFormat . GetDisplayName ( ) , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
357356
358357 using ( logger . BeginScope ( "Calculating statistics" ) )
359358 {
@@ -381,7 +380,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
381380 return result . Diagnostic . Errors . Count == 0 ;
382381 }
383382
384- private static async Task < ReadResult > ParseOpenApiAsync ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
383+ private static async Task < ReadResult > ParseOpenApiAsync ( string openApiFile , string format , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
385384 {
386385 ReadResult result ;
387386 var stopwatch = Stopwatch . StartNew ( ) ;
@@ -397,7 +396,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
397396 new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
398397 } ;
399398
400- var format = OpenApiModelFactory . GetFormat ( openApiFile ) ;
401399 result = await OpenApiDocument . LoadAsync ( stream , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
402400
403401 logger . LogTrace ( "{Timestamp}ms: Completed parsing." , stopwatch . ElapsedMilliseconds ) ;
@@ -588,8 +586,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
588586 throw new ArgumentException ( "Please input a file path or URL" ) ;
589587 }
590588
591- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
592- var document = await GetOpenApiAsync ( options , format , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
589+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
590+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
593591
594592 using ( logger . BeginScope ( "Creating diagram" ) )
595593 {
@@ -749,9 +747,11 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
749747 options . OpenApi = apiDependency . ApiDescriptionUrl ;
750748 }
751749
750+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi )
751+ ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
752+
752753 // Load OpenAPI document
753- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
754- var document = await GetOpenApiAsync ( options , format , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
754+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
755755
756756 cancellationToken . ThrowIfCancellationRequested ( ) ;
757757
0 commit comments