77using System . IO ;
88using System . Net ;
99using System . Net . Http ;
10+ using System . Reflection ;
1011using System . Security ;
1112using System . Text ;
12- using System . Threading . Tasks ;
1313using System . Text . Json ;
14- using Microsoft . Extensions . Logging ;
14+ using System . Threading ;
15+ using System . Threading . Tasks ;
16+ using System . Xml ;
1517using System . Xml . Linq ;
18+ using System . Xml . Xsl ;
19+ using Microsoft . Extensions . Configuration ;
20+ using Microsoft . Extensions . Logging ;
1621using Microsoft . OData . Edm . Csdl ;
1722using Microsoft . OpenApi . Extensions ;
1823using Microsoft . OpenApi . Models ;
2126using Microsoft . OpenApi . Services ;
2227using Microsoft . OpenApi . Writers ;
2328using static Microsoft . OpenApi . Hidi . OpenApiSpecVersionHelper ;
24- using System . Threading ;
25- using System . Xml . Xsl ;
26- using System . Xml ;
27- using System . Reflection ;
28- using Microsoft . Extensions . Configuration ;
2929
3030namespace Microsoft . OpenApi . Hidi
3131{
@@ -98,7 +98,7 @@ CancellationToken cancellationToken
9898 }
9999 }
100100
101- private static void WriteOpenApi ( FileInfo output , bool terseOutput , bool inlineLocal , bool inlineExternal , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger )
101+ private static void WriteOpenApi ( FileInfo output , bool terseOutput , bool inlineLocal , bool inlineExternal , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger )
102102 {
103103 using ( logger . BeginScope ( "Output" ) )
104104 {
@@ -135,7 +135,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
135135 {
136136 OpenApiDocument document ;
137137 Stream stream ;
138-
138+
139139 if ( ! string . IsNullOrEmpty ( csdl ) )
140140 {
141141 var stopwatch = new Stopwatch ( ) ;
@@ -168,7 +168,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
168168 return document ;
169169 }
170170
171- private static async Task < OpenApiDocument > FilterOpenApiDocument ( string filterbyoperationids , string filterbytags , string filterbycollection , OpenApiDocument document , ILogger logger , CancellationToken cancellationToken )
171+ private static async Task < OpenApiDocument > FilterOpenApiDocument ( string filterbyoperationids , string filterbytags , string filterbycollection , OpenApiDocument document , ILogger logger , CancellationToken cancellationToken )
172172 {
173173 using ( logger . BeginScope ( "Filter" ) )
174174 {
@@ -239,8 +239,8 @@ private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSin
239239 /// Implementation of the validate command
240240 /// </summary>
241241 public static async Task ValidateOpenApiDocument (
242- string openapi ,
243- ILogger logger ,
242+ string openapi ,
243+ ILogger logger ,
244244 CancellationToken cancellationToken )
245245 {
246246 if ( string . IsNullOrEmpty ( openapi ) )
@@ -285,7 +285,7 @@ private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inli
285285 result = await new OpenApiStreamReader ( new OpenApiReaderSettings
286286 {
287287 LoadExternalRefs = inlineExternal ,
288- BaseUrl = openApiFile . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) ?
288+ BaseUrl = openApiFile . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) ?
289289 new Uri ( openApiFile ) :
290290 new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
291291 }
@@ -296,7 +296,7 @@ private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inli
296296 LogErrors ( logger , result ) ;
297297 stopwatch . Stop ( ) ;
298298 }
299-
299+
300300 return result ;
301301 }
302302
@@ -310,7 +310,7 @@ internal static IConfiguration GetConfiguration(string settingsFile)
310310
311311 return config ;
312312 }
313-
313+
314314 /// <summary>
315315 /// Converts CSDL to OpenAPI
316316 /// </summary>
@@ -329,7 +329,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
329329 {
330330 settings . SemVerVersion = metadataVersion ;
331331 }
332-
332+
333333 config . GetSection ( "OpenApiConvertSettings" ) . Bind ( settings ) ;
334334
335335 OpenApiDocument document = edmModel . ConvertToOpenApi ( settings ) ;
@@ -354,7 +354,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document)
354354
355355 return doc ;
356356 }
357-
357+
358358 /// <summary>
359359 /// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
360360 /// </summary>
@@ -377,13 +377,13 @@ public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream st
377377 private static Dictionary < string , List < string > > EnumerateJsonDocument ( JsonElement itemElement , Dictionary < string , List < string > > paths )
378378 {
379379 var itemsArray = itemElement . GetProperty ( "item" ) ;
380-
380+
381381 foreach ( var item in itemsArray . EnumerateArray ( ) )
382382 {
383- if ( item . ValueKind == JsonValueKind . Object )
383+ if ( item . ValueKind == JsonValueKind . Object )
384384 {
385- if ( item . TryGetProperty ( "request" , out var request ) )
386- {
385+ if ( item . TryGetProperty ( "request" , out var request ) )
386+ {
387387 // Fetch list of methods and urls from collection, store them in a dictionary
388388 var path = request . GetProperty ( "url" ) . GetProperty ( "raw" ) . ToString ( ) ;
389389 var method = request . GetProperty ( "method" ) . ToString ( ) ;
@@ -395,11 +395,11 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
395395 {
396396 paths [ path ] . Add ( method ) ;
397397 }
398- }
399- else
400- {
398+ }
399+ else
400+ {
401401 EnumerateJsonDocument ( item , paths ) ;
402- }
402+ }
403403 }
404404 else
405405 {
@@ -508,11 +508,11 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
508508 if ( output == null )
509509 {
510510 var tempPath = Path . GetTempPath ( ) + "/hidi/" ;
511- if ( ! File . Exists ( tempPath ) )
511+ if ( ! File . Exists ( tempPath ) )
512512 {
513513 Directory . CreateDirectory ( tempPath ) ;
514- }
515-
514+ }
515+
516516 var fileName = Path . GetRandomFileName ( ) ;
517517
518518 output = new FileInfo ( Path . Combine ( tempPath , fileName + ".html" ) ) ;
@@ -528,7 +528,7 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
528528 process . StartInfo . FileName = output . FullName ;
529529 process . StartInfo . UseShellExecute = true ;
530530 process . Start ( ) ;
531-
531+
532532 return output . FullName ;
533533 }
534534 else // Write diagram as Markdown document to output file
@@ -540,7 +540,7 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
540540 }
541541 logger . LogTrace ( "Created markdown document with diagram " ) ;
542542 return output . FullName ;
543- }
543+ }
544544 }
545545 }
546546 catch ( TaskCanceledException )
@@ -563,7 +563,7 @@ private static void LogErrors(ILogger logger, ReadResult result)
563563 {
564564 foreach ( var error in context . Errors )
565565 {
566- logger . LogError ( $ "Detected error during parsing: { error } ", error . ToString ( ) ) ;
566+ logger . LogError ( $ "Detected error during parsing: { error } ", error . ToString ( ) ) ;
567567 }
568568 }
569569 }
@@ -581,7 +581,7 @@ internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocum
581581 // write a span for each mermaidcolorscheme
582582 foreach ( var style in OpenApiUrlTreeNode . MermaidNodeStyles )
583583 {
584- writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " ) } </span>") ;
584+ writer . WriteLine ( $ "<span style=\" padding:2px;background-color:{ style . Value . Color } ;border: 2px solid\" >{ style . Key . Replace ( "_" , " " ) } </span>") ;
585585 }
586586 writer . WriteLine ( "</div>" ) ;
587587 writer . WriteLine ( ) ;
@@ -609,7 +609,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
609609 writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
610610 writer . WriteLine ( ) ;
611611 writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
612-
612+
613613 writer . WriteLine ( @"<div>" ) ;
614614 // write a span for each mermaidcolorscheme
615615 foreach ( var style in OpenApiUrlTreeNode . MermaidNodeStyles )
@@ -622,8 +622,8 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
622622 rootNode . WriteMermaid ( writer ) ;
623623 writer . WriteLine ( "</code>" ) ;
624624
625- // Write script tag to include JS library for rendering markdown
626- writer . WriteLine ( @"<script>
625+ // Write script tag to include JS library for rendering markdown
626+ writer . WriteLine ( @"<script>
627627 var config = {
628628 startOnLoad:true,
629629 theme: 'forest',
@@ -635,8 +635,8 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
635635 mermaid.initialize(config);
636636 window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
637637 </script>" ) ;
638- // Write script tag to include JS library for rendering mermaid
639- writer . WriteLine ( "</html" ) ;
638+ // Write script tag to include JS library for rendering mermaid
639+ writer . WriteLine ( "</html" ) ;
640640 }
641641 }
642642}
0 commit comments