2222using Microsoft . OData . Edm . Csdl ;
2323using Microsoft . OpenApi . ApiManifest ;
2424using Microsoft . OpenApi . ApiManifest . OpenAI ;
25+ using Microsoft . OpenApi . ApiManifest . OpenAI . Authentication ;
2526using Microsoft . OpenApi . Extensions ;
2627using Microsoft . OpenApi . Hidi . Extensions ;
2728using Microsoft . OpenApi . Hidi . Formatters ;
@@ -66,7 +67,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
6667
6768#pragma warning restore CA1308 // Normalize strings to uppercase
6869 options . Output = new ( $ "./output{ inputExtension } ") ;
69- } ;
70+ }
7071
7172 if ( options . CleanOutput && options . Output . Exists )
7273 {
@@ -85,7 +86,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
8586 var apiDependency = await FindApiDependencyAsync ( options . FilterOptions . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
8687 if ( apiDependency != null )
8788 {
88- options . OpenApi = apiDependency . ApiDescripionUrl ;
89+ options . OpenApi = apiDependency . ApiDescriptionUrl ;
8990 }
9091
9192 // If Postman Collection is provided, load it
@@ -97,8 +98,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9798 }
9899
99100 // Load OpenAPI document
100- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
101- 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 ) ;
102102
103103 if ( options . FilterOptions != null )
104104 {
@@ -254,8 +254,8 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
254254 else if ( ! string . IsNullOrEmpty ( options . OpenApi ) )
255255 {
256256 stream = await GetStreamAsync ( options . OpenApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
257- var result = await ParseOpenApiAsync ( options . OpenApi , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
258- document = result . OpenApiDocument ;
257+ var result = await ParseOpenApiAsync ( options . OpenApi , format , options . InlineExternal , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
258+ document = result . Document ;
259259 }
260260 else throw new InvalidOperationException ( "No input file path or URL provided" ) ;
261261
@@ -351,14 +351,14 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
351351 try
352352 {
353353 using var stream = await GetStreamAsync ( openApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
354-
355- 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 ) ;
356356
357357 using ( logger . BeginScope ( "Calculating statistics" ) )
358358 {
359359 var statsVisitor = new StatsVisitor ( ) ;
360360 var walker = new OpenApiWalker ( statsVisitor ) ;
361- walker . Walk ( result . OpenApiDocument ) ;
361+ walker . Walk ( result . Document ) ;
362362
363363 logger . LogTrace ( "Finished walking through the OpenApi document. Generating a statistics report.." ) ;
364364 #pragma warning disable CA2254
@@ -377,10 +377,10 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
377377
378378 if ( result is null ) return null ;
379379
380- return result . OpenApiDiagnostic . Errors . Count == 0 ;
380+ return result . Diagnostic . Errors . Count == 0 ;
381381 }
382382
383- 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 )
384384 {
385385 ReadResult result ;
386386 var stopwatch = Stopwatch . StartNew ( ) ;
@@ -396,7 +396,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
396396 new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
397397 } ;
398398
399- var format = OpenApiModelFactory . GetFormat ( openApiFile ) ;
400399 result = await OpenApiDocument . LoadAsync ( stream , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
401400
402401 logger . LogTrace ( "{Timestamp}ms: Completed parsing." , stopwatch . ElapsedMilliseconds ) ;
@@ -439,7 +438,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document, string for
439438 var sb = new StringBuilder ( ) ;
440439 document . SerializeAsV3 ( new OpenApiYamlWriter ( new StringWriter ( sb ) ) ) ;
441440
442- var doc = OpenApiDocument . Parse ( sb . ToString ( ) , format ) . OpenApiDocument ;
441+ var doc = OpenApiDocument . Parse ( sb . ToString ( ) , format ) . Document ;
443442
444443 return doc ;
445444 }
@@ -587,8 +586,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
587586 throw new ArgumentException ( "Please input a file path or URL" ) ;
588587 }
589588
590- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
591- 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 ) ;
592591
593592 using ( logger . BeginScope ( "Creating diagram" ) )
594593 {
@@ -649,7 +648,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
649648
650649 private static void LogErrors ( ILogger logger , ReadResult result )
651650 {
652- var context = result . OpenApiDiagnostic ;
651+ var context = result . Diagnostic ;
653652 if ( context . Errors . Count != 0 )
654653 {
655654 using ( logger . BeginScope ( "Detected errors" ) )
@@ -745,12 +744,14 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
745744 var apiDependency = await FindApiDependencyAsync ( options . FilterOptions ? . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
746745 if ( apiDependency != null )
747746 {
748- options . OpenApi = apiDependency . ApiDescripionUrl ;
747+ options . OpenApi = apiDependency . ApiDescriptionUrl ;
749748 }
750749
750+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi )
751+ ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
752+
751753 // Load OpenAPI document
752- var format = OpenApiModelFactory . GetFormat ( options . OpenApi ) ;
753- 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 ) ;
754755
755756 cancellationToken . ThrowIfCancellationRequested ( ) ;
756757
@@ -771,15 +772,11 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
771772 WriteOpenApi ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_1 , document , logger ) ;
772773
773774 // Create OpenAIPluginManifest from ApiDependency and OpenAPI document
774- var manifest = new OpenAIPluginManifest
775+ var manifest = new OpenAIPluginManifest ( document . Info ? . Title ?? "Title" , document . Info ? . Title ?? "Title" , "https://go.microsoft.com/fwlink/?LinkID=288890" , document . Info ? . Contact ? . Email ?? "[email protected] " , document . Info ? . License ? . Url . ToString ( ) ?? "https://placeholderlicenseurl.com" ) 775776 {
776- NameForHuman = document . Info . Title ,
777- DescriptionForHuman = document . Info . Description ,
778- Api = new ( )
779- {
780- Type = "openapi" ,
781- Url = "./openapi.json"
782- }
777+ DescriptionForHuman = document . Info ? . Description ?? "Description placeholder" ,
778+ Api = new ( "openapi" , "./openapi.json" ) ,
779+ Auth = new ManifestNoAuth ( ) ,
783780 } ;
784781 manifest . NameForModel = manifest . NameForHuman ;
785782 manifest . DescriptionForModel = manifest . DescriptionForHuman ;
0 commit comments