22
22
using Microsoft . OpenApi . Services ;
23
23
using Microsoft . OpenApi . Validations ;
24
24
using Microsoft . OpenApi . Writers ;
25
+ using static Microsoft . OpenApi . Hidi . OpenApiSpecVersionExtension ;
25
26
26
27
namespace Microsoft . OpenApi . Hidi
27
28
{
@@ -31,7 +32,7 @@ public static async Task ProcessOpenApiDocument(
31
32
string openapi ,
32
33
string csdl ,
33
34
FileInfo output ,
34
- OpenApiSpecVersion ? version ,
35
+ string ? version ,
35
36
OpenApiFormat ? format ,
36
37
LogLevel loglevel ,
37
38
bool inline ,
@@ -83,13 +84,14 @@ string filterbycollection
83
84
Stream stream ;
84
85
OpenApiDocument document ;
85
86
OpenApiFormat openApiFormat ;
87
+ OpenApiSpecVersion ? openApiVersion = null ;
86
88
var stopwatch = new Stopwatch ( ) ;
87
89
88
90
if ( ! string . IsNullOrEmpty ( csdl ) )
89
91
{
90
92
// Default to yaml and OpenApiVersion 3 during csdl to OpenApi conversion
91
93
openApiFormat = format ?? GetOpenApiFormat ( csdl , logger ) ;
92
- version ??= OpenApiSpecVersion . OpenApi3_0 ;
94
+ openApiVersion = version . TryParseOpenApiSpecVersion ( ) ;
93
95
94
96
stream = await GetStream ( csdl , logger ) ;
95
97
document = await ConvertCsdlToOpenApi ( stream ) ;
@@ -128,7 +130,7 @@ string filterbycollection
128
130
}
129
131
130
132
openApiFormat = format ?? GetOpenApiFormat ( openapi , logger ) ;
131
- version ??= result . OpenApiDiagnostic . SpecificationVersion ;
133
+ openApiVersion ??= result . OpenApiDiagnostic . SpecificationVersion ;
132
134
}
133
135
134
136
Func < string , OperationType ? , OpenApiOperation , bool > predicate ;
@@ -185,14 +187,14 @@ string filterbycollection
185
187
logger . LogTrace ( "Serializing to OpenApi document using the provided spec version and writer" ) ;
186
188
187
189
stopwatch . Start ( ) ;
188
- document . Serialize ( writer , ( OpenApiSpecVersion ) version ) ;
190
+ document . Serialize ( writer , ( OpenApiSpecVersion ) openApiVersion ) ;
189
191
stopwatch . Stop ( ) ;
190
192
191
193
logger . LogTrace ( $ "Finished serializing in { stopwatch . ElapsedMilliseconds } ms") ;
192
194
193
195
textWriter . Flush ( ) ;
194
196
}
195
-
197
+
196
198
/// <summary>
197
199
/// Converts CSDL to OpenAPI
198
200
/// </summary>
0 commit comments