@@ -41,7 +41,7 @@ internal static class OpenApiService
41
41
/// <summary>
42
42
/// Implementation of the transform command
43
43
/// </summary>
44
- public static async Task TransformOpenApiDocument ( HidiOptions options , ILogger logger , CancellationToken cancellationToken )
44
+ public static async Task TransformOpenApiDocument ( HidiOptions options , ILogger logger , CancellationToken cancellationToken = default )
45
45
{
46
46
if ( string . IsNullOrEmpty ( options . OpenApi ) && string . IsNullOrEmpty ( options . Csdl ) && string . IsNullOrEmpty ( options . FilterOptions ? . FilterByApiManifest ) )
47
47
{
@@ -85,7 +85,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
85
85
}
86
86
87
87
// Load OpenAPI document
88
- OpenApiDocument document = await GetOpenApi ( options , logger , cancellationToken , options . MetadataVersion ) . ConfigureAwait ( false ) ;
88
+ OpenApiDocument document = await GetOpenApi ( options , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
89
89
90
90
if ( options . FilterOptions != null )
91
91
{
@@ -116,7 +116,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
116
116
}
117
117
}
118
118
119
- private static async Task < ApiDependency ? > FindApiDependency ( string ? apiManifestPath , ILogger logger , CancellationToken cancellationToken )
119
+ private static async Task < ApiDependency ? > FindApiDependency ( string ? apiManifestPath , ILogger logger , CancellationToken cancellationToken = default )
120
120
{
121
121
ApiDependency ? apiDependency = null ;
122
122
// If API Manifest is provided, load it, use it get the OpenAPI path
@@ -186,7 +186,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
186
186
using var outputStream = options . Output . Create ( ) ;
187
187
using var textWriter = new StreamWriter ( outputStream ) ;
188
188
189
- var settings = new OpenApiWriterSettings ( )
189
+ var settings = new OpenApiWriterSettings
190
190
{
191
191
InlineLocalReferences = options . InlineLocal ,
192
192
InlineExternalReferences = options . InlineExternal
@@ -212,7 +212,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
212
212
}
213
213
214
214
// Get OpenAPI document either from OpenAPI or CSDL
215
- private static async Task < OpenApiDocument > GetOpenApi ( HidiOptions options , ILogger logger , CancellationToken cancellationToken , string ? metadataVersion = null )
215
+ private static async Task < OpenApiDocument > GetOpenApi ( HidiOptions options , ILogger logger , string ? metadataVersion = null , CancellationToken cancellationToken = default )
216
216
{
217
217
218
218
OpenApiDocument document ;
@@ -326,7 +326,7 @@ private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSin
326
326
public static async Task ValidateOpenApiDocument (
327
327
string openApi ,
328
328
ILogger logger ,
329
- CancellationToken cancellationToken )
329
+ CancellationToken cancellationToken = default )
330
330
{
331
331
if ( string . IsNullOrEmpty ( openApi ) )
332
332
{
@@ -361,7 +361,7 @@ public static async Task ValidateOpenApiDocument(
361
361
}
362
362
}
363
363
364
- private static async Task < ReadResult > ParseOpenApi ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken )
364
+ private static async Task < ReadResult > ParseOpenApi ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
365
365
{
366
366
ReadResult result ;
367
367
Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
@@ -480,7 +480,7 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
480
480
/// <summary>
481
481
/// Reads stream from file system or makes HTTP request depending on the input string
482
482
/// </summary>
483
- private static async Task < Stream > GetStream ( string input , ILogger logger , CancellationToken cancellationToken )
483
+ private static async Task < Stream > GetStream ( string input , ILogger logger , CancellationToken cancellationToken = default )
484
484
{
485
485
Stream stream ;
486
486
using ( logger . BeginScope ( "Reading input stream" ) )
@@ -510,13 +510,15 @@ private static async Task<Stream> GetStream(string input, ILogger logger, Cancel
510
510
var fileInput = new FileInfo ( input ) ;
511
511
stream = fileInput . OpenRead ( ) ;
512
512
}
513
- catch ( Exception ex ) when ( ex is FileNotFoundException ||
514
- ex is PathTooLongException ||
515
- ex is DirectoryNotFoundException ||
516
- ex is IOException ||
517
- ex is UnauthorizedAccessException ||
518
- ex is SecurityException ||
519
- ex is NotSupportedException )
513
+ catch ( Exception ex ) when (
514
+ ex is
515
+ FileNotFoundException or
516
+ PathTooLongException or
517
+ DirectoryNotFoundException or
518
+ IOException or
519
+ UnauthorizedAccessException or
520
+ SecurityException or
521
+ NotSupportedException )
520
522
{
521
523
throw new InvalidOperationException ( $ "Could not open the file at { input } ", ex ) ;
522
524
}
@@ -554,7 +556,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
554
556
return extension ;
555
557
}
556
558
557
- internal static async Task < string ? > ShowOpenApiDocument ( HidiOptions options , ILogger logger , CancellationToken cancellationToken )
559
+ internal static async Task < string ? > ShowOpenApiDocument ( HidiOptions options , ILogger logger , CancellationToken cancellationToken = default )
558
560
{
559
561
try
560
562
{
@@ -563,7 +565,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
563
565
throw new ArgumentException ( "Please input a file path or URL" ) ;
564
566
}
565
567
566
- var document = await GetOpenApi ( options , logger , cancellationToken ) . ConfigureAwait ( false ) ;
568
+ var document = await GetOpenApi ( options , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
567
569
568
570
using ( logger . BeginScope ( "Creating diagram" ) )
569
571
{
@@ -662,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
662
664
{
663
665
var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
664
666
665
- writer . WriteLine ( @"<!doctype html>
666
- <html>
667
- <head>
668
- <meta charset=""utf-8""/>
669
- <script src=""https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js""></script>
670
- </head>
671
- <style>
672
- body {
673
- font-family: Verdana, sans-serif;
674
- }
675
- </style>
676
- <body>" ) ;
667
+ writer . WriteLine (
668
+ """
669
+ <!doctype html>
670
+ <html>
671
+ <head>
672
+ <meta charset="utf-8"/>
673
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js"></script>
674
+ </head>
675
+ <style>
676
+ body {
677
+ font-family: Verdana, sans-serif;
678
+ }
679
+ </style>
680
+ <body>
681
+ """ ) ;
677
682
writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
678
683
writer . WriteLine ( ) ;
679
684
writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
@@ -684,30 +689,34 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
684
689
{
685
690
writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " , StringComparison . OrdinalIgnoreCase ) } </span>") ;
686
691
}
692
+
687
693
writer . WriteLine ( "</div>" ) ;
688
694
writer . WriteLine ( "<hr/>" ) ;
689
695
writer . WriteLine ( "<code class=\" language-mermaid\" >" ) ;
690
696
rootNode . WriteMermaid ( writer ) ;
691
697
writer . WriteLine ( "</code>" ) ;
692
698
693
699
// Write script tag to include JS library for rendering markdown
694
- writer . WriteLine ( @"<script>
695
- var config = {
696
- startOnLoad:true,
697
- theme: 'forest',
698
- flowchart:{
699
- useMaxWidth:false,
700
- htmlLabels:true
701
- }
702
- };
703
- mermaid.initialize(config);
704
- window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
705
- </script>" ) ;
700
+ writer . WriteLine (
701
+ """
702
+ <script>
703
+ var config = {
704
+ startOnLoad:true,
705
+ theme: 'forest',
706
+ flowchart:{
707
+ useMaxWidth:false,
708
+ htmlLabels:true
709
+ }
710
+ };
711
+ mermaid.initialize(config);
712
+ window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
713
+ </script>
714
+ """ ) ;
706
715
// Write script tag to include JS library for rendering mermaid
707
716
writer . WriteLine ( "</html" ) ;
708
717
}
709
718
710
- internal static async Task PluginManifest ( HidiOptions options , ILogger logger , CancellationToken cancellationToken )
719
+ internal static async Task PluginManifest ( HidiOptions options , ILogger logger , CancellationToken cancellationToken = default )
711
720
{
712
721
// If ApiManifest is provided, set the referenced OpenAPI document
713
722
var apiDependency = await FindApiDependency ( options . FilterOptions ? . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -717,7 +726,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
717
726
}
718
727
719
728
// Load OpenAPI document
720
- OpenApiDocument document = await GetOpenApi ( options , logger , cancellationToken , options . MetadataVersion ) . ConfigureAwait ( false ) ;
729
+ OpenApiDocument document = await GetOpenApi ( options , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
721
730
722
731
cancellationToken . ThrowIfCancellationRequested ( ) ;
723
732
@@ -738,7 +747,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
738
747
WriteOpenApi ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_0 , document , logger ) ;
739
748
740
749
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
741
- var manifest = new OpenAIPluginManifest ( )
750
+ var manifest = new OpenAIPluginManifest
742
751
{
743
752
NameForHuman = document . Info . Title ,
744
753
DescriptionForHuman = document . Info . Description ,
0 commit comments