@@ -55,7 +55,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
5555 if ( options . Output == null )
5656 {
5757#pragma warning disable CA1308 // Normalize strings to uppercase
58- var extension = options . OpenApiFormat ? . GetDisplayName ( ) . ToLowerInvariant ( ) ;
58+ var extension = options . OpenApiFormat ? . ToLowerInvariant ( ) ;
5959 var inputExtension = ! string . IsNullOrEmpty ( extension ) ? string . Concat ( "." , extension )
6060 : GetInputPathExtension ( options . OpenApi , options . Csdl ) ;
6161
@@ -73,7 +73,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
7373 }
7474
7575 // Default to yaml and OpenApiVersion 3_1 during csdl to OpenApi conversion
76- var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
76+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiConstants . Yaml ) ;
7777 var openApiVersion = options . Version != null ? TryParseOpenApiSpecVersion ( options . Version ) : OpenApiSpecVersion . OpenApi3_1 ;
7878
7979 // If ApiManifest is provided, set the referenced OpenAPI document
@@ -92,7 +92,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9292 }
9393
9494 // Load OpenAPI document
95- var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
95+ var document = await GetOpenApiAsync ( options , openApiFormat , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
9696
9797 if ( options . FilterOptions != null && document is not null )
9898 {
@@ -189,7 +189,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
189189 return document ;
190190 }
191191
192- private static async Task WriteOpenApiAsync ( HidiOptions options , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger , CancellationToken cancellationToken )
192+ private static async Task WriteOpenApiAsync ( HidiOptions options , string openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger , CancellationToken cancellationToken )
193193 {
194194 using ( logger . BeginScope ( "Output" ) )
195195 {
@@ -202,11 +202,12 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o
202202 InlineLocalReferences = options . InlineLocal ,
203203 InlineExternalReferences = options . InlineExternal
204204 } ;
205-
206- IOpenApiWriter writer = openApiFormat switch
205+ #pragma warning disable CA1308
206+ IOpenApiWriter writer = openApiFormat . ToLowerInvariant ( ) switch
207+ #pragma warning restore CA1308
207208 {
208- OpenApiFormat . Json => options . TerseOutput ? new ( textWriter , settings , options . TerseOutput ) : new OpenApiJsonWriter ( textWriter , settings , false ) ,
209- OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
209+ OpenApiConstants . Json => options . TerseOutput ? new ( textWriter , settings , options . TerseOutput ) : new OpenApiJsonWriter ( textWriter , settings , false ) ,
210+ OpenApiConstants . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
210211 _ => throw new ArgumentException ( "Unknown format" ) ,
211212 } ;
212213
@@ -560,10 +561,10 @@ SecurityException or
560561 /// <param name="input"></param>
561562 /// <param name="logger"></param>
562563 /// <returns></returns>
563- private static OpenApiFormat GetOpenApiFormat ( string input , ILogger logger )
564+ private static string GetOpenApiFormat ( string input , ILogger logger )
564565 {
565566 logger . LogTrace ( "Getting the OpenApi format" ) ;
566- return ! input . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) && Path . GetExtension ( input ) == ".json" ? OpenApiFormat . Json : OpenApiFormat . Yaml ;
567+ return ! input . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) && Path . GetExtension ( input ) == ".json" ? OpenApiConstants . Json : OpenApiConstants . Yaml ;
567568 }
568569
569570 private static string GetInputPathExtension ( string ? openapi = null , string ? csdl = null )
@@ -590,8 +591,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
590591 throw new ArgumentException ( "Please input a file path or URL" ) ;
591592 }
592593
593- var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
594- var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
594+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi ) ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiConstants . Yaml ) ;
595+ var document = await GetOpenApiAsync ( options , openApiFormat , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
595596 if ( document is not null )
596597 {
597598 using ( logger . BeginScope ( "Creating diagram" ) )
@@ -754,10 +755,10 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
754755 }
755756
756757 var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi )
757- ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
758+ ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiConstants . Yaml ) ;
758759
759760 // Load OpenAPI document
760- var document = await GetOpenApiAsync ( options , openApiFormat . GetDisplayName ( ) , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
761+ var document = await GetOpenApiAsync ( options , openApiFormat , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
761762
762763 cancellationToken . ThrowIfCancellationRequested ( ) ;
763764
@@ -777,7 +778,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
777778 options . TerseOutput = true ;
778779 if ( document is not null )
779780 {
780- await WriteOpenApiAsync ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_1 , document , logger , cancellationToken ) . ConfigureAwait ( false ) ;
781+ await WriteOpenApiAsync ( options , OpenApiConstants . Json , OpenApiSpecVersion . OpenApi3_1 , document , logger , cancellationToken ) . ConfigureAwait ( false ) ;
781782
782783 // Create OpenAIPluginManifest from ApiDependency and OpenAPI document
783784 var manifest = new OpenAIPluginManifest ( document . Info . Title ?? "Title" ,
0 commit comments