@@ -85,11 +85,11 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
85
85
}
86
86
87
87
// Load OpenAPI document
88
- OpenApiDocument document = await GetOpenApi ( options . OpenApi , options . Csdl , options . CsdlFilter , options . SettingsConfig , options . InlineExternal , logger , cancellationToken , options . MetadataVersion ) ;
88
+ OpenApiDocument document = await GetOpenApi ( options , logger , cancellationToken , options . MetadataVersion ) ;
89
89
90
90
if ( options . FilterOptions != null )
91
91
{
92
- document = ApplyFilters ( options , logger , apiDependency , postmanCollection , document , cancellationToken ) ;
92
+ document = ApplyFilters ( options , logger , apiDependency , postmanCollection , document ) ;
93
93
}
94
94
95
95
var languageFormat = options . SettingsConfig ? . GetSection ( "LanguageFormat" ) ? . Value ;
@@ -100,7 +100,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
100
100
var walker = new OpenApiWalker ( powerShellFormatter ) ;
101
101
walker . Walk ( document ) ;
102
102
}
103
- WriteOpenApi ( options . Output , options . TerseOutput , options . InlineLocal , options . InlineExternal , openApiFormat , openApiVersion , document , logger ) ;
103
+ WriteOpenApi ( options , openApiFormat , openApiVersion , document , logger ) ;
104
104
}
105
105
catch ( TaskCanceledException )
106
106
{
@@ -141,7 +141,7 @@ private static async Task<ApiDependency> FindApiDependency(string apiManifestPat
141
141
return apiDependency ;
142
142
}
143
143
144
- private static OpenApiDocument ApplyFilters ( HidiOptions options , ILogger logger , ApiDependency apiDependency , JsonDocument postmanCollection , OpenApiDocument document , CancellationToken cancellationToken )
144
+ private static OpenApiDocument ApplyFilters ( HidiOptions options , ILogger logger , ApiDependency apiDependency , JsonDocument postmanCollection , OpenApiDocument document )
145
145
{
146
146
Dictionary < string , List < string > > requestUrls = null ;
147
147
if ( apiDependency != null )
@@ -172,22 +172,22 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
172
172
return document ;
173
173
}
174
174
175
- private static void WriteOpenApi ( FileInfo output , bool terseOutput , bool inlineLocal , bool inlineExternal , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger )
175
+ private static void WriteOpenApi ( HidiOptions options , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger )
176
176
{
177
177
using ( logger . BeginScope ( "Output" ) )
178
178
{
179
- using var outputStream = output . Create ( ) ;
179
+ using var outputStream = options . Output . Create ( ) ;
180
180
var textWriter = new StreamWriter ( outputStream ) ;
181
181
182
182
var settings = new OpenApiWriterSettings ( )
183
183
{
184
- InlineLocalReferences = inlineLocal ,
185
- InlineExternalReferences = inlineExternal
184
+ InlineLocalReferences = options . InlineLocal ,
185
+ InlineExternalReferences = options . InlineExternal
186
186
} ;
187
187
188
188
IOpenApiWriter writer = openApiFormat switch
189
189
{
190
- OpenApiFormat . Json => terseOutput ? new OpenApiJsonWriter ( textWriter , settings , terseOutput ) : new OpenApiJsonWriter ( textWriter , settings , false ) ,
190
+ OpenApiFormat . Json => options . TerseOutput ? new OpenApiJsonWriter ( textWriter , settings , options . TerseOutput ) : new OpenApiJsonWriter ( textWriter , settings , false ) ,
191
191
OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
192
192
_ => throw new ArgumentException ( "Unknown format" ) ,
193
193
} ;
@@ -205,37 +205,38 @@ private static void WriteOpenApi(FileInfo output, bool terseOutput, bool inlineL
205
205
}
206
206
207
207
// Get OpenAPI document either from OpenAPI or CSDL
208
- private static async Task < OpenApiDocument > GetOpenApi ( string openapi , string csdl , string csdlFilter , IConfiguration settings , bool inlineExternal , ILogger logger , CancellationToken cancellationToken , string metadataVersion = null )
208
+ private static async Task < OpenApiDocument > GetOpenApi ( HidiOptions options , ILogger logger , CancellationToken cancellationToken , string metadataVersion = null )
209
209
{
210
+
210
211
OpenApiDocument document ;
211
212
Stream stream ;
212
213
213
- if ( ! string . IsNullOrEmpty ( csdl ) )
214
+ if ( ! string . IsNullOrEmpty ( options . Csdl ) )
214
215
{
215
216
var stopwatch = new Stopwatch ( ) ;
216
- using ( logger . BeginScope ( $ "Convert CSDL: { csdl } ", csdl ) )
217
+ using ( logger . BeginScope ( $ "Convert CSDL: { options . Csdl } ", options . Csdl ) )
217
218
{
218
219
stopwatch . Start ( ) ;
219
- stream = await GetStream ( csdl , logger , cancellationToken ) ;
220
+ stream = await GetStream ( options . Csdl , logger , cancellationToken ) ;
220
221
Stream filteredStream = null ;
221
- if ( ! string . IsNullOrEmpty ( csdlFilter ) )
222
+ if ( ! string . IsNullOrEmpty ( options . CsdlFilter ) )
222
223
{
223
224
XslCompiledTransform transform = GetFilterTransform ( ) ;
224
- filteredStream = ApplyFilterToCsdl ( stream , csdlFilter , transform ) ;
225
+ filteredStream = ApplyFilterToCsdl ( stream , options . CsdlFilter , transform ) ;
225
226
filteredStream . Position = 0 ;
226
227
stream . Dispose ( ) ;
227
228
stream = null ;
228
229
}
229
230
230
- document = await ConvertCsdlToOpenApi ( filteredStream ?? stream , metadataVersion , settings , cancellationToken ) ;
231
+ document = await ConvertCsdlToOpenApi ( filteredStream ?? stream , metadataVersion , options . SettingsConfig , cancellationToken ) ;
231
232
stopwatch . Stop ( ) ;
232
233
logger . LogTrace ( "{timestamp}ms: Generated OpenAPI with {paths} paths." , stopwatch . ElapsedMilliseconds , document . Paths . Count ) ;
233
234
}
234
235
}
235
236
else
236
237
{
237
- stream = await GetStream ( openapi , logger , cancellationToken ) ;
238
- var result = await ParseOpenApi ( openapi , inlineExternal , logger , stream , cancellationToken ) ;
238
+ stream = await GetStream ( options . OpenApi , logger , cancellationToken ) ;
239
+ var result = await ParseOpenApi ( options . OpenApi , options . InlineExternal , logger , stream , cancellationToken ) ;
239
240
document = result . OpenApiDocument ;
240
241
}
241
242
@@ -548,21 +549,21 @@ private static string GetInputPathExtension(string openapi = null, string csdl =
548
549
return extension ;
549
550
}
550
551
551
- internal static async Task < string > ShowOpenApiDocument ( string openapi , string csdl , string csdlFilter , FileInfo output , ILogger logger , CancellationToken cancellationToken )
552
+ internal static async Task < string > ShowOpenApiDocument ( HidiOptions options , ILogger logger , CancellationToken cancellationToken )
552
553
{
553
554
try
554
555
{
555
- if ( string . IsNullOrEmpty ( openapi ) && string . IsNullOrEmpty ( csdl ) )
556
+ if ( string . IsNullOrEmpty ( options . OpenApi ) && string . IsNullOrEmpty ( options . Csdl ) )
556
557
{
557
558
throw new ArgumentException ( "Please input a file path or URL" ) ;
558
559
}
559
560
560
- var document = await GetOpenApi ( openapi , csdl , csdlFilter , null , false , logger , cancellationToken ) ;
561
+ var document = await GetOpenApi ( options , logger , cancellationToken ) ;
561
562
562
563
using ( logger . BeginScope ( "Creating diagram" ) )
563
564
{
564
565
// If output is null, create a HTML file in the user's temporary directory
565
- if ( output == null )
566
+ if ( options . Output == null )
566
567
{
567
568
var tempPath = Path . GetTempPath ( ) + "/hidi/" ;
568
569
if ( ! File . Exists ( tempPath ) )
@@ -572,11 +573,11 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
572
573
573
574
var fileName = Path . GetRandomFileName ( ) ;
574
575
575
- output = new FileInfo ( Path . Combine ( tempPath , fileName + ".html" ) ) ;
576
+ var output = new FileInfo ( Path . Combine ( tempPath , fileName + ".html" ) ) ;
576
577
using ( var file = new FileStream ( output . FullName , FileMode . Create ) )
577
578
{
578
579
using var writer = new StreamWriter ( file ) ;
579
- WriteTreeDocumentAsHtml ( openapi ?? csdl , document , writer ) ;
580
+ WriteTreeDocumentAsHtml ( options . OpenApi ?? options . Csdl , document , writer ) ;
580
581
}
581
582
logger . LogTrace ( "Created Html document with diagram " ) ;
582
583
@@ -590,13 +591,13 @@ internal static async Task<string> ShowOpenApiDocument(string openapi, string cs
590
591
}
591
592
else // Write diagram as Markdown document to output file
592
593
{
593
- using ( var file = new FileStream ( output . FullName , FileMode . Create ) )
594
+ using ( var file = new FileStream ( options . Output . FullName , FileMode . Create ) )
594
595
{
595
596
using var writer = new StreamWriter ( file ) ;
596
- WriteTreeDocumentAsMarkdown ( openapi ?? csdl , document , writer ) ;
597
+ WriteTreeDocumentAsMarkdown ( options . OpenApi ?? options . Csdl , document , writer ) ;
597
598
}
598
599
logger . LogTrace ( "Created markdown document with diagram " ) ;
599
- return output . FullName ;
600
+ return options . Output . FullName ;
600
601
}
601
602
}
602
603
}
@@ -705,13 +706,13 @@ internal async static Task PluginManifest(HidiOptions options, ILogger logger, C
705
706
}
706
707
707
708
// Load OpenAPI document
708
- OpenApiDocument document = await GetOpenApi ( options . OpenApi , options . Csdl , options . CsdlFilter , options . SettingsConfig , options . InlineExternal , logger , cancellationToken , options . MetadataVersion ) ;
709
+ OpenApiDocument document = await GetOpenApi ( options , logger , cancellationToken , options . MetadataVersion ) ;
709
710
710
711
cancellationToken . ThrowIfCancellationRequested ( ) ;
711
712
712
713
if ( options . FilterOptions != null )
713
714
{
714
- document = ApplyFilters ( options , logger , apiDependency , null , document , cancellationToken ) ;
715
+ document = ApplyFilters ( options , logger , apiDependency , null , document ) ;
715
716
}
716
717
717
718
// Ensure path in options.OutputFolder exists
@@ -722,7 +723,8 @@ internal async static Task PluginManifest(HidiOptions options, ILogger logger, C
722
723
}
723
724
var slicedOpenApi = new FileInfo ( Path . Combine ( options . OutputFolder , "openapi.json" ) ) ;
724
725
// Write OpenAPI to Output folder
725
- WriteOpenApi ( slicedOpenApi , true , options . InlineLocal , options . InlineExternal , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_0 , document , logger ) ;
726
+ options . TerseOutput = true ;
727
+ WriteOpenApi ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_0 , document , logger ) ;
726
728
727
729
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
728
730
var manifest = new OpenAIPluginManifest ( ) {
0 commit comments