@@ -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
@@ -186,7 +186,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
186186 using var outputStream = options . Output . Create ( ) ;
187187 using var textWriter = new StreamWriter ( outputStream ) ;
188188
189- var settings = new OpenApiWriterSettings ( )
189+ var settings = new OpenApiWriterSettings
190190 {
191191 InlineLocalReferences = options . InlineLocal ,
192192 InlineExternalReferences = options . InlineExternal
@@ -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" ) )
@@ -510,13 +510,15 @@ private static async Task<Stream> GetStream(string input, ILogger logger, Cancel
510510 var fileInput = new FileInfo ( input ) ;
511511 stream = fileInput . OpenRead ( ) ;
512512 }
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 )
520522 {
521523 throw new InvalidOperationException ( $ "Could not open the file at { input } ", ex ) ;
522524 }
@@ -554,7 +556,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
554556 return extension ;
555557 }
556558
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 )
558560 {
559561 try
560562 {
@@ -563,7 +565,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
563565 throw new ArgumentException ( "Please input a file path or URL" ) ;
564566 }
565567
566- var document = await GetOpenApi ( options , logger , cancellationToken ) . ConfigureAwait ( false ) ;
568+ var document = await GetOpenApi ( options , logger , null , cancellationToken ) . ConfigureAwait ( false ) ;
567569
568570 using ( logger . BeginScope ( "Creating diagram" ) )
569571 {
@@ -662,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
662664 {
663665 var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
664666
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+ """ ) ;
677682 writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
678683 writer . WriteLine ( ) ;
679684 writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
@@ -684,30 +689,34 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
684689 {
685690 writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " , StringComparison . OrdinalIgnoreCase ) } </span>") ;
686691 }
692+
687693 writer . WriteLine ( "</div>" ) ;
688694 writer . WriteLine ( "<hr/>" ) ;
689695 writer . WriteLine ( "<code class=\" language-mermaid\" >" ) ;
690696 rootNode . WriteMermaid ( writer ) ;
691697 writer . WriteLine ( "</code>" ) ;
692698
693699 // 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+ """ ) ;
706715 // Write script tag to include JS library for rendering mermaid
707716 writer . WriteLine ( "</html" ) ;
708717 }
709718
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 )
711720 {
712721 // If ApiManifest is provided, set the referenced OpenAPI document
713722 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
717726 }
718727
719728 // 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 ) ;
721730
722731 cancellationToken . ThrowIfCancellationRequested ( ) ;
723732
@@ -738,7 +747,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
738747 WriteOpenApi ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_0 , document , logger ) ;
739748
740749 // Create OpenAIPluginManifest from ApiDependency and OpenAPI document
741- var manifest = new OpenAIPluginManifest ( )
750+ var manifest = new OpenAIPluginManifest
742751 {
743752 NameForHuman = document . Info . Title ,
744753 DescriptionForHuman = document . Info . Description ,
0 commit comments