@@ -21,8 +21,8 @@ static class OpenApiService
21
21
public static void ProcessOpenApiDocument (
22
22
string input ,
23
23
FileInfo output ,
24
- OpenApiSpecVersion version ,
25
- OpenApiFormat format ,
24
+ OpenApiSpecVersion ? version ,
25
+ OpenApiFormat ? format ,
26
26
string filterByOperationIds ,
27
27
string filterByTags ,
28
28
bool inline ,
@@ -91,13 +91,16 @@ public static void ProcessOpenApiDocument(
91
91
{
92
92
ReferenceInline = inline ? ReferenceInlineSetting . InlineLocalReferences : ReferenceInlineSetting . DoNotInlineReferences
93
93
} ;
94
- IOpenApiWriter writer = format switch
94
+
95
+ var openApiFormat = format ?? GetOpenApiFormat ( input ) ;
96
+ var openApiVersion = version ?? result . OpenApiDiagnostic . SpecificationVersion ;
97
+ IOpenApiWriter writer = openApiFormat switch
95
98
{
96
99
OpenApiFormat . Json => new OpenApiJsonWriter ( textWriter , settings ) ,
97
100
OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
98
101
_ => throw new ArgumentException ( "Unknown format" ) ,
99
102
} ;
100
- document . Serialize ( writer , version ) ;
103
+ document . Serialize ( writer , openApiVersion ) ;
101
104
102
105
textWriter . Flush ( ) ;
103
106
}
@@ -156,5 +159,17 @@ internal static void ValidateOpenApiDocument(string input)
156
159
157
160
Console . WriteLine ( statsVisitor . GetStatisticsReport ( ) ) ;
158
161
}
162
+
163
+ private static OpenApiFormat GetOpenApiFormat ( string input )
164
+ {
165
+ if ( ! input . StartsWith ( "http" ) && Path . GetExtension ( input ) == ".json" )
166
+ {
167
+ return OpenApiFormat . Json ;
168
+ }
169
+ else
170
+ {
171
+ return OpenApiFormat . Yaml ;
172
+ }
173
+ }
159
174
}
160
175
}
0 commit comments