@@ -21,8 +21,8 @@ static class OpenApiService
2121 public static void ProcessOpenApiDocument (
2222 string input ,
2323 FileInfo output ,
24- OpenApiSpecVersion version ,
25- OpenApiFormat format ,
24+ OpenApiSpecVersion ? version ,
25+ OpenApiFormat ? format ,
2626 string filterByOperationIds ,
2727 string filterByTags ,
2828 bool inline ,
@@ -91,13 +91,16 @@ public static void ProcessOpenApiDocument(
9191 {
9292 ReferenceInline = inline ? ReferenceInlineSetting . InlineLocalReferences : ReferenceInlineSetting . DoNotInlineReferences
9393 } ;
94- IOpenApiWriter writer = format switch
94+
95+ var openApiFormat = format ?? GetOpenApiFormat ( input ) ;
96+ var openApiVersion = version ?? result . OpenApiDiagnostic . SpecificationVersion ;
97+ IOpenApiWriter writer = openApiFormat switch
9598 {
9699 OpenApiFormat . Json => new OpenApiJsonWriter ( textWriter , settings ) ,
97100 OpenApiFormat . Yaml => new OpenApiYamlWriter ( textWriter , settings ) ,
98101 _ => throw new ArgumentException ( "Unknown format" ) ,
99102 } ;
100- document . Serialize ( writer , version ) ;
103+ document . Serialize ( writer , openApiVersion ) ;
101104
102105 textWriter . Flush ( ) ;
103106 }
@@ -156,5 +159,17 @@ internal static void ValidateOpenApiDocument(string input)
156159
157160 Console . WriteLine ( statsVisitor . GetStatisticsReport ( ) ) ;
158161 }
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+ }
159174 }
160175}
0 commit comments