@@ -41,7 +41,7 @@ internal static class OpenApiService
4141 /// <summary>
4242 /// Implementation of the transform command
4343 /// </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 )
4545 {
4646 if ( string . IsNullOrEmpty ( options . OpenApi ) && string . IsNullOrEmpty ( options . Csdl ) && string . IsNullOrEmpty ( options . FilterOptions ? . FilterByApiManifest ) )
4747 {
@@ -85,7 +85,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
8585 }
8686
8787 // 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 ) ;
8989
9090 if ( options . FilterOptions != null )
9191 {
@@ -116,7 +116,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
116116 }
117117 }
118118
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 )
120120 {
121121 ApiDependency ? apiDependency = null ;
122122 // 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
212212 }
213213
214214 // 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 )
216216 {
217217
218218 OpenApiDocument document ;
@@ -326,7 +326,7 @@ private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSin
326326 public static async Task ValidateOpenApiDocument (
327327 string openApi ,
328328 ILogger logger ,
329- CancellationToken cancellationToken )
329+ CancellationToken cancellationToken = default )
330330 {
331331 if ( string . IsNullOrEmpty ( openApi ) )
332332 {
@@ -361,7 +361,7 @@ public static async Task ValidateOpenApiDocument(
361361 }
362362 }
363363
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 )
365365 {
366366 ReadResult result ;
367367 Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
@@ -480,7 +480,7 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
480480 /// <summary>
481481 /// Reads stream from file system or makes HTTP request depending on the input string
482482 /// </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 )
484484 {
485485 Stream stream ;
486486 using ( logger . BeginScope ( "Reading input stream" ) )
@@ -556,7 +556,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
556556 return extension ;
557557 }
558558
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 )
560560 {
561561 try
562562 {
@@ -565,7 +565,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
565565 throw new ArgumentException ( "Please input a file path or URL" ) ;
566566 }
567567
568- var document = await GetOpenApi ( options , logger , cancellationToken ) . ConfigureAwait ( false ) ;
568+ var document = await GetOpenApi ( options , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
569569
570570 using ( logger . BeginScope ( "Creating diagram" ) )
571571 {
@@ -664,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
664664 {
665665 var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
666666
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+ """ ) ;
679682 writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
680683 writer . WriteLine ( ) ;
681684 writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
@@ -686,30 +689,34 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
686689 {
687690 writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " , StringComparison . OrdinalIgnoreCase ) } </span>") ;
688691 }
692+
689693 writer . WriteLine ( "</div>" ) ;
690694 writer . WriteLine ( "<hr/>" ) ;
691695 writer . WriteLine ( "<code class=\" language-mermaid\" >" ) ;
692696 rootNode . WriteMermaid ( writer ) ;
693697 writer . WriteLine ( "</code>" ) ;
694698
695699 // 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+ """ ) ;
708715 // Write script tag to include JS library for rendering mermaid
709716 writer . WriteLine ( "</html" ) ;
710717 }
711718
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 )
713720 {
714721 // If ApiManifest is provided, set the referenced OpenAPI document
715722 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
719726 }
720727
721728 // 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 ) ;
723730
724731 cancellationToken . ThrowIfCancellationRequested ( ) ;
725732
0 commit comments