7
7
using System . IO ;
8
8
using System . Net ;
9
9
using System . Net . Http ;
10
+ using System . Reflection ;
10
11
using System . Security ;
11
12
using System . Text ;
12
- using System . Threading . Tasks ;
13
13
using System . Text . Json ;
14
- using Microsoft . Extensions . Logging ;
14
+ using System . Threading ;
15
+ using System . Threading . Tasks ;
16
+ using System . Xml ;
15
17
using System . Xml . Linq ;
18
+ using System . Xml . Xsl ;
19
+ using Microsoft . Extensions . Configuration ;
20
+ using Microsoft . Extensions . Logging ;
16
21
using Microsoft . OData . Edm . Csdl ;
17
22
using Microsoft . OpenApi . Extensions ;
18
23
using Microsoft . OpenApi . Models ;
21
26
using Microsoft . OpenApi . Services ;
22
27
using Microsoft . OpenApi . Writers ;
23
28
using 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 ;
29
29
30
30
namespace Microsoft . OpenApi . Hidi
31
31
{
@@ -98,7 +98,7 @@ CancellationToken cancellationToken
98
98
}
99
99
}
100
100
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 )
102
102
{
103
103
using ( logger . BeginScope ( "Output" ) )
104
104
{
@@ -135,7 +135,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
135
135
{
136
136
OpenApiDocument document ;
137
137
Stream stream ;
138
-
138
+
139
139
if ( ! string . IsNullOrEmpty ( csdl ) )
140
140
{
141
141
var stopwatch = new Stopwatch ( ) ;
@@ -168,7 +168,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
168
168
return document ;
169
169
}
170
170
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 )
172
172
{
173
173
using ( logger . BeginScope ( "Filter" ) )
174
174
{
@@ -239,8 +239,8 @@ private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSin
239
239
/// Implementation of the validate command
240
240
/// </summary>
241
241
public static async Task ValidateOpenApiDocument (
242
- string openapi ,
243
- ILogger logger ,
242
+ string openapi ,
243
+ ILogger logger ,
244
244
CancellationToken cancellationToken )
245
245
{
246
246
if ( string . IsNullOrEmpty ( openapi ) )
@@ -285,7 +285,7 @@ private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inli
285
285
result = await new OpenApiStreamReader ( new OpenApiReaderSettings
286
286
{
287
287
LoadExternalRefs = inlineExternal ,
288
- BaseUrl = openApiFile . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) ?
288
+ BaseUrl = openApiFile . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) ?
289
289
new Uri ( openApiFile ) :
290
290
new Uri ( "file://" + new FileInfo ( openApiFile ) . DirectoryName + Path . DirectorySeparatorChar )
291
291
}
@@ -296,7 +296,7 @@ private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inli
296
296
LogErrors ( logger , result ) ;
297
297
stopwatch . Stop ( ) ;
298
298
}
299
-
299
+
300
300
return result ;
301
301
}
302
302
@@ -310,7 +310,7 @@ internal static IConfiguration GetConfiguration(string settingsFile)
310
310
311
311
return config ;
312
312
}
313
-
313
+
314
314
/// <summary>
315
315
/// Converts CSDL to OpenAPI
316
316
/// </summary>
@@ -329,7 +329,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
329
329
{
330
330
settings . SemVerVersion = metadataVersion ;
331
331
}
332
-
332
+
333
333
config . GetSection ( "OpenApiConvertSettings" ) . Bind ( settings ) ;
334
334
335
335
OpenApiDocument document = edmModel . ConvertToOpenApi ( settings ) ;
@@ -354,7 +354,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document)
354
354
355
355
return doc ;
356
356
}
357
-
357
+
358
358
/// <summary>
359
359
/// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
360
360
/// </summary>
@@ -377,13 +377,13 @@ public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream st
377
377
private static Dictionary < string , List < string > > EnumerateJsonDocument ( JsonElement itemElement , Dictionary < string , List < string > > paths )
378
378
{
379
379
var itemsArray = itemElement . GetProperty ( "item" ) ;
380
-
380
+
381
381
foreach ( var item in itemsArray . EnumerateArray ( ) )
382
382
{
383
- if ( item . ValueKind == JsonValueKind . Object )
383
+ if ( item . ValueKind == JsonValueKind . Object )
384
384
{
385
- if ( item . TryGetProperty ( "request" , out var request ) )
386
- {
385
+ if ( item . TryGetProperty ( "request" , out var request ) )
386
+ {
387
387
// Fetch list of methods and urls from collection, store them in a dictionary
388
388
var path = request . GetProperty ( "url" ) . GetProperty ( "raw" ) . ToString ( ) ;
389
389
var method = request . GetProperty ( "method" ) . ToString ( ) ;
@@ -395,11 +395,11 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
395
395
{
396
396
paths [ path ] . Add ( method ) ;
397
397
}
398
- }
399
- else
400
- {
398
+ }
399
+ else
400
+ {
401
401
EnumerateJsonDocument ( item , paths ) ;
402
- }
402
+ }
403
403
}
404
404
else
405
405
{
@@ -508,11 +508,11 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
508
508
if ( output == null )
509
509
{
510
510
var tempPath = Path . GetTempPath ( ) + "/hidi/" ;
511
- if ( ! File . Exists ( tempPath ) )
511
+ if ( ! File . Exists ( tempPath ) )
512
512
{
513
513
Directory . CreateDirectory ( tempPath ) ;
514
- }
515
-
514
+ }
515
+
516
516
var fileName = Path . GetRandomFileName ( ) ;
517
517
518
518
output = new FileInfo ( Path . Combine ( tempPath , fileName + ".html" ) ) ;
@@ -528,7 +528,7 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
528
528
process . StartInfo . FileName = output . FullName ;
529
529
process . StartInfo . UseShellExecute = true ;
530
530
process . Start ( ) ;
531
-
531
+
532
532
return output . FullName ;
533
533
}
534
534
else // Write diagram as Markdown document to output file
@@ -540,7 +540,7 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
540
540
}
541
541
logger . LogTrace ( "Created markdown document with diagram " ) ;
542
542
return output . FullName ;
543
- }
543
+ }
544
544
}
545
545
}
546
546
catch ( TaskCanceledException )
@@ -563,7 +563,7 @@ private static void LogErrors(ILogger logger, ReadResult result)
563
563
{
564
564
foreach ( var error in context . Errors )
565
565
{
566
- logger . LogError ( $ "Detected error during parsing: { error } ", error . ToString ( ) ) ;
566
+ logger . LogError ( $ "Detected error during parsing: { error } ", error . ToString ( ) ) ;
567
567
}
568
568
}
569
569
}
@@ -581,7 +581,7 @@ internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocum
581
581
// write a span for each mermaidcolorscheme
582
582
foreach ( var style in OpenApiUrlTreeNode . MermaidNodeStyles )
583
583
{
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>") ;
585
585
}
586
586
writer . WriteLine ( "</div>" ) ;
587
587
writer . WriteLine ( ) ;
@@ -609,7 +609,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
609
609
writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
610
610
writer . WriteLine ( ) ;
611
611
writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
612
-
612
+
613
613
writer . WriteLine ( @"<div>" ) ;
614
614
// write a span for each mermaidcolorscheme
615
615
foreach ( var style in OpenApiUrlTreeNode . MermaidNodeStyles )
@@ -622,8 +622,8 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
622
622
rootNode . WriteMermaid ( writer ) ;
623
623
writer . WriteLine ( "</code>" ) ;
624
624
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>
627
627
var config = {
628
628
startOnLoad:true,
629
629
theme: 'forest',
@@ -635,8 +635,8 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
635
635
mermaid.initialize(config);
636
636
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
637
637
</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" ) ;
640
640
}
641
641
}
642
642
}
0 commit comments