@@ -66,7 +66,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
6666
6767#pragma warning restore CA1308 // Normalize strings to uppercase
6868 options . Output = new ( $ "./output{ inputExtension } ") ;
69- } ;
69+ }
7070
7171 if ( options . CleanOutput && options . Output . Exists )
7272 {
@@ -97,8 +97,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9797 }
9898
9999 // Load OpenAPI document
100- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
101- var document = await GetOpenApiAsync ( options , format , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
100+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
102101
103102 if ( options . FilterOptions != null )
104103 {
@@ -254,7 +253,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
254253 else if ( ! string . IsNullOrEmpty ( options . OpenApi ) )
255254 {
256255 stream = await GetStreamAsync ( options . OpenApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
257- var result = await ParseOpenApiAsync ( options . OpenApi , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
256+ var result = await ParseOpenApiAsync ( options . OpenApi , format , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
258257 document = result . OpenApiDocument ;
259258 }
260259 else throw new InvalidOperationException ( "No input file path or URL provided" ) ;
@@ -351,8 +350,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
351350 try
352351 {
353352 using var stream = await GetStreamAsync ( openApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
354-
355- result = await ParseOpenApiAsync ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
353+ var openApiFormat = ! string . IsNullOrEmpty ( openApi ) ? GetOpenApiFormat ( openApi , logger ) : OpenApiFormat . Yaml ;
354+ result = await ParseOpenApiAsync ( openApi , openApiFormat . GetDisplayName ( ) , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
356355
357356 using ( logger . BeginScope ( "Calculating statistics" ) )
358357 {
@@ -380,7 +379,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
380379 return result . OpenApiDiagnostic . Errors . Count == 0 ;
381380 }
382381
383- private static async Task < ReadResult > ParseOpenApiAsync ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
382+ private static async Task < ReadResult > ParseOpenApiAsync ( string openApiFile , string format , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
384383 {
385384 ReadResult result ;
386385 var stopwatch = Stopwatch . StartNew ( ) ;
@@ -396,7 +395,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
396395 new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
397396 } ;
398397
399- var format = OpenApiModelFactory . GetFormat ( openApiFile ) ;
400398 result = await OpenApiDocument . LoadAsync ( stream , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
401399
402400 logger . LogTrace ( "{Timestamp}ms: Completed parsing." , stopwatch . ElapsedMilliseconds ) ;
@@ -587,8 +585,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
587585 throw new ArgumentException ( "Please input a file path or URL" ) ;
588586 }
589587
590- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
591- var document = await GetOpenApiAsync ( options , format , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
588+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
589+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
592590
593591 using ( logger . BeginScope ( "Creating diagram" ) )
594592 {
@@ -748,9 +746,11 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
748746 options . OpenApi = apiDependency . ApiDescripionUrl ;
749747 }
750748
749+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi )
750+ ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
751+
751752 // Load OpenAPI document
752- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
753- var document = await GetOpenApiAsync ( options , format , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
753+ var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
754754
755755 cancellationToken . ThrowIfCancellationRequested ( ) ;
756756
0 commit comments