@@ -23,8 +23,8 @@ public static class OpenApiService
23
23
public static void ProcessOpenApiDocument (
24
24
string input ,
25
25
FileInfo output ,
26
- OpenApiSpecVersion version ,
27
- OpenApiFormat format ,
26
+ OpenApiSpecVersion ? version ,
27
+ OpenApiFormat ? format ,
28
28
string filterByOperationIds ,
29
29
string filterByTags ,
30
30
string filterByCollection ,
@@ -101,13 +101,16 @@ public static void ProcessOpenApiDocument(
101
101
{
102
102
ReferenceInline = inline ? ReferenceInlineSetting . InlineLocalReferences : ReferenceInlineSetting . DoNotInlineReferences
103
103
} ;
104
- IOpenApiWriter writer = format switch
104
+
105
+ var openApiFormat = format ?? GetOpenApiFormat ( input ) ;
106
+ var openApiVersion = version ?? result . OpenApiDiagnostic . SpecificationVersion ;
107
+ IOpenApiWriter writer = openApiFormat switch
105
108
{
106
109
OpenApiFormat . Json => new OpenApiJsonWriter ( textWriter , settings ) ,
107
110
OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
108
111
_ => throw new ArgumentException ( "Unknown format" ) ,
109
112
} ;
110
- document . Serialize ( writer , version ) ;
113
+ document . Serialize ( writer , openApiVersion ) ;
111
114
112
115
textWriter . Flush ( ) ;
113
116
}
@@ -198,5 +201,17 @@ internal static void ValidateOpenApiDocument(string input)
198
201
199
202
Console . WriteLine ( statsVisitor . GetStatisticsReport ( ) ) ;
200
203
}
204
+
205
+ private static OpenApiFormat GetOpenApiFormat ( string input )
206
+ {
207
+ if ( ! input . StartsWith ( "http" ) && Path . GetExtension ( input ) == ".json" )
208
+ {
209
+ return OpenApiFormat . Json ;
210
+ }
211
+ else
212
+ {
213
+ return OpenApiFormat . Yaml ;
214
+ }
215
+ }
201
216
}
202
217
}
0 commit comments