22
22
using Microsoft . OData . Edm . Csdl ;
23
23
using Microsoft . OpenApi . ApiManifest ;
24
24
using Microsoft . OpenApi . ApiManifest . OpenAI ;
25
+ using Microsoft . OpenApi . ApiManifest . OpenAI . Authentication ;
25
26
using Microsoft . OpenApi . Extensions ;
26
27
using Microsoft . OpenApi . Hidi . Extensions ;
27
28
using Microsoft . OpenApi . Hidi . Formatters ;
@@ -66,7 +67,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
66
67
67
68
#pragma warning restore CA1308 // Normalize strings to uppercase
68
69
options . Output = new ( $ "./output{ inputExtension } ") ;
69
- } ;
70
+ }
70
71
71
72
if ( options . CleanOutput && options . Output . Exists )
72
73
{
@@ -85,7 +86,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
85
86
var apiDependency = await FindApiDependencyAsync ( options . FilterOptions . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
86
87
if ( apiDependency != null )
87
88
{
88
- options . OpenApi = apiDependency . ApiDescripionUrl ;
89
+ options . OpenApi = apiDependency . ApiDescriptionUrl ;
89
90
}
90
91
91
92
// If Postman Collection is provided, load it
@@ -97,8 +98,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
97
98
}
98
99
99
100
// 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 ) ;
102
102
103
103
if ( options . FilterOptions != null )
104
104
{
@@ -254,8 +254,8 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
254
254
else if ( ! string . IsNullOrEmpty ( options . OpenApi ) )
255
255
{
256
256
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 ;
259
259
}
260
260
else throw new InvalidOperationException ( "No input file path or URL provided" ) ;
261
261
@@ -351,14 +351,14 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
351
351
try
352
352
{
353
353
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 ) ;
356
356
357
357
using ( logger . BeginScope ( "Calculating statistics" ) )
358
358
{
359
359
var statsVisitor = new StatsVisitor ( ) ;
360
360
var walker = new OpenApiWalker ( statsVisitor ) ;
361
- walker . Walk ( result . OpenApiDocument ) ;
361
+ walker . Walk ( result . Document ) ;
362
362
363
363
logger . LogTrace ( "Finished walking through the OpenApi document. Generating a statistics report.." ) ;
364
364
#pragma warning disable CA2254
@@ -377,10 +377,10 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
377
377
378
378
if ( result is null ) return null ;
379
379
380
- return result . OpenApiDiagnostic . Errors . Count == 0 ;
380
+ return result . Diagnostic . Errors . Count == 0 ;
381
381
}
382
382
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 )
384
384
{
385
385
ReadResult result ;
386
386
var stopwatch = Stopwatch . StartNew ( ) ;
@@ -396,7 +396,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
396
396
new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
397
397
} ;
398
398
399
- var format = OpenApiModelFactory . GetFormat ( openApiFile ) ;
400
399
result = await OpenApiDocument . LoadAsync ( stream , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
401
400
402
401
logger . LogTrace ( "{Timestamp}ms: Completed parsing." , stopwatch . ElapsedMilliseconds ) ;
@@ -439,7 +438,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document, string for
439
438
var sb = new StringBuilder ( ) ;
440
439
document . SerializeAsV3 ( new OpenApiYamlWriter ( new StringWriter ( sb ) ) ) ;
441
440
442
- var doc = OpenApiDocument . Parse ( sb . ToString ( ) , format ) . OpenApiDocument ;
441
+ var doc = OpenApiDocument . Parse ( sb . ToString ( ) , format ) . Document ;
443
442
444
443
return doc ;
445
444
}
@@ -587,8 +586,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
587
586
throw new ArgumentException ( "Please input a file path or URL" ) ;
588
587
}
589
588
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 ) ;
592
591
593
592
using ( logger . BeginScope ( "Creating diagram" ) )
594
593
{
@@ -649,7 +648,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
649
648
650
649
private static void LogErrors ( ILogger logger , ReadResult result )
651
650
{
652
- var context = result . OpenApiDiagnostic ;
651
+ var context = result . Diagnostic ;
653
652
if ( context . Errors . Count != 0 )
654
653
{
655
654
using ( logger . BeginScope ( "Detected errors" ) )
@@ -745,12 +744,14 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
745
744
var apiDependency = await FindApiDependencyAsync ( options . FilterOptions ? . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
746
745
if ( apiDependency != null )
747
746
{
748
- options . OpenApi = apiDependency . ApiDescripionUrl ;
747
+ options . OpenApi = apiDependency . ApiDescriptionUrl ;
749
748
}
750
749
750
+ var openApiFormat = options . OpenApiFormat ?? ( ! string . IsNullOrEmpty ( options . OpenApi )
751
+ ? GetOpenApiFormat ( options . OpenApi , logger ) : OpenApiFormat . Yaml ) ;
752
+
751
753
// 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 ) ;
754
755
755
756
cancellationToken . ThrowIfCancellationRequested ( ) ;
756
757
@@ -771,15 +772,11 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
771
772
WriteOpenApi ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_1 , document , logger ) ;
772
773
773
774
// 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" )
775
776
{
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 ( ) ,
783
780
} ;
784
781
manifest . NameForModel = manifest . NameForHuman ;
785
782
manifest . DescriptionForModel = manifest . DescriptionForHuman ;
0 commit comments