@@ -23,8 +23,8 @@ public static class OpenApiService
2323 public static void ProcessOpenApiDocument (
2424 string input ,
2525 FileInfo output ,
26- OpenApiSpecVersion version ,
27- OpenApiFormat format ,
26+ OpenApiSpecVersion ? version ,
27+ OpenApiFormat ? format ,
2828 string filterByOperationIds ,
2929 string filterByTags ,
3030 string filterByCollection ,
@@ -101,13 +101,16 @@ public static void ProcessOpenApiDocument(
101101 {
102102 ReferenceInline = inline ? ReferenceInlineSetting . InlineLocalReferences : ReferenceInlineSetting . DoNotInlineReferences
103103 } ;
104- IOpenApiWriter writer = format switch
104+
105+ var openApiFormat = format ?? GetOpenApiFormat ( input ) ;
106+ var openApiVersion = version ?? result . OpenApiDiagnostic . SpecificationVersion ;
107+ IOpenApiWriter writer = openApiFormat switch
105108 {
106109 OpenApiFormat . Json => new OpenApiJsonWriter ( textWriter , settings ) ,
107110 OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
108111 _ => throw new ArgumentException ( "Unknown format" ) ,
109112 } ;
110- document . Serialize ( writer , version ) ;
113+ document . Serialize ( writer , openApiVersion ) ;
111114
112115 textWriter . Flush ( ) ;
113116 }
@@ -198,5 +201,17 @@ internal static void ValidateOpenApiDocument(string input)
198201
199202 Console . WriteLine ( statsVisitor . GetStatisticsReport ( ) ) ;
200203 }
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+ }
201216 }
202217}
0 commit comments