@@ -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
@@ -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" ) )
@@ -556,7 +556,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
556
556
return extension ;
557
557
}
558
558
559
- 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 )
560
560
{
561
561
try
562
562
{
@@ -565,7 +565,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
565
565
throw new ArgumentException ( "Please input a file path or URL" ) ;
566
566
}
567
567
568
- var document = await GetOpenApi ( options , logger , cancellationToken ) . ConfigureAwait ( false ) ;
568
+ var document = await GetOpenApi ( options , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
569
569
570
570
using ( logger . BeginScope ( "Creating diagram" ) )
571
571
{
@@ -664,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
664
664
{
665
665
var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
666
666
667
- writer . WriteLine ( @"<!doctype html>
668
- <html>
669
- <head>
670
- <meta charset=""utf-8""/>
671
- <script src=""https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js""></script>
672
- </head>
673
- <style>
674
- body {
675
- font-family: Verdana, sans-serif;
676
- }
677
- </style>
678
- <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
+ """ ) ;
679
682
writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
680
683
writer . WriteLine ( ) ;
681
684
writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
@@ -686,30 +689,34 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
686
689
{
687
690
writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " , StringComparison . OrdinalIgnoreCase ) } </span>") ;
688
691
}
692
+
689
693
writer . WriteLine ( "</div>" ) ;
690
694
writer . WriteLine ( "<hr/>" ) ;
691
695
writer . WriteLine ( "<code class=\" language-mermaid\" >" ) ;
692
696
rootNode . WriteMermaid ( writer ) ;
693
697
writer . WriteLine ( "</code>" ) ;
694
698
695
699
// Write script tag to include JS library for rendering markdown
696
- writer . WriteLine ( @"<script>
697
- var config = {
698
- startOnLoad:true,
699
- theme: 'forest',
700
- flowchart:{
701
- useMaxWidth:false,
702
- htmlLabels:true
703
- }
704
- };
705
- mermaid.initialize(config);
706
- window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
707
- </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
+ """ ) ;
708
715
// Write script tag to include JS library for rendering mermaid
709
716
writer . WriteLine ( "</html" ) ;
710
717
}
711
718
712
- internal static async Task PluginManifest ( HidiOptions options , ILogger logger , CancellationToken cancellationToken )
719
+ internal static async Task PluginManifest ( HidiOptions options , ILogger logger , CancellationToken cancellationToken = default )
713
720
{
714
721
// If ApiManifest is provided, set the referenced OpenAPI document
715
722
var apiDependency = await FindApiDependency ( options . FilterOptions ? . FilterByApiManifest , logger , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -719,7 +726,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
719
726
}
720
727
721
728
// Load OpenAPI document
722
- OpenApiDocument document = await GetOpenApi ( options , logger , cancellationToken , options . MetadataVersion ) . ConfigureAwait ( false ) ;
729
+ OpenApiDocument document = await GetOpenApi ( options , logger , options . MetadataVersion , cancellationToken ) . ConfigureAwait ( false ) ;
723
730
724
731
cancellationToken . ThrowIfCancellationRequested ( ) ;
725
732
0 commit comments