@@ -19,6 +19,9 @@ static Task<int> Main(string[] args)
1919 var output = new Option < string > ( name : "--output" , description : "The output file path." ,
2020 getDefaultValue : ( ) => "swagger.json" ) ;
2121
22+ var useTagForOutput = new Option < bool > ( name : "--use-tag-for-output" , description : "If set to true the output file will be named with the readmeTag used for the run" ,
23+ getDefaultValue : ( ) => false ) ;
24+
2225 var readmeFile = new Option < string > ( name : "--readme" , "The input readme file." ) ;
2326
2427 var readmeTag = new Option < string > ( name : "--tag" , description : "Readme tag used to generate swagger apiView" ,
@@ -37,6 +40,7 @@ static Task<int> Main(string[] args)
3740 {
3841 swaggers ,
3942 output ,
43+ useTagForOutput ,
4044 packageName ,
4145 swaggerLinks ,
4246 readmeFile ,
@@ -46,7 +50,7 @@ static Task<int> Main(string[] args)
4650
4751 cmd . Description = "Parse swagger file into codefile." ;
4852
49- cmd . SetHandler ( async ( IEnumerable < string > swaggerFiles , string outputFile , string package , IEnumerable < string > links , string readme , string tag ) =>
53+ cmd . SetHandler ( async ( IEnumerable < string > swaggerFiles , string outputFile , bool useTagForOutputFileName , string package , IEnumerable < string > links , string readme , string tag ) =>
5054 {
5155 var swaggerLinksArray = links . ToList ( ) ;
5256
@@ -56,20 +60,20 @@ static Task<int> Main(string[] args)
5660 {
5761 readme = Path . GetFullPath ( readme ) ;
5862 }
59- await HandleGenerateCodeFile ( enumerable , outputFile , package , swaggerLinksArray , readme , tag ) ;
60- } , swaggers , output , packageName , swaggerLinks , readmeFile , readmeTag ) ;
63+ await HandleGenerateCodeFile ( enumerable , outputFile , useTagForOutputFileName , package , swaggerLinksArray , readme , tag ) ;
64+ } , swaggers , output , useTagForOutput , packageName , swaggerLinks , readmeFile , readmeTag ) ;
6165
6266 return Task . FromResult ( cmd . Invoke ( args ) ) ;
6367 }
6468
65- static async Task HandleGenerateCodeFile ( IEnumerable < string > swaggers , string output , string packageName , List < string > swaggerLinks , string readmeFile , string readmeTag )
69+ static async Task HandleGenerateCodeFile ( IEnumerable < string > swaggers , string output , bool useTagForOutput , string packageName , List < string > swaggerLinks , string readmeFile , string readmeTag )
6670 {
6771
6872 var swaggerFilePaths = swaggers . ToList ( ) ;
6973 if ( readmeFile != null )
7074 {
7175 var readmeFileDir = Path . GetDirectoryName ( readmeFile ) ;
72- var swaggerFiles = ReadmeParser . GetSwaggerFilesFromReadme ( readmeFile , readmeTag ) ;
76+ var swaggerFiles = ReadmeParser . GetSwaggerFilesFromReadme ( readmeFile , ref readmeTag ) ;
7377 swaggerFilePaths = swaggerFilePaths . Concat ( swaggerFiles . Select ( it => Path . Join ( readmeFileDir , it ) ) ) . ToList ( ) ;
7478 }
7579
@@ -114,6 +118,13 @@ static async Task HandleGenerateCodeFile(IEnumerable<string> swaggers, string ou
114118
115119 var codeFile = root . GenerateCodeFile ( ) ;
116120 var outputFilePath = Path . GetFullPath ( output ) ;
121+
122+ if ( useTagForOutput )
123+ {
124+ output = $ "{ readmeTag } .json";
125+ outputFilePath = Path . Combine ( Path . GetDirectoryName ( outputFilePath ) , output ) ;
126+ }
127+
117128 await using FileStream writer = File . Open ( outputFilePath , FileMode . Create ) ;
118129 Console . WriteLine ( $ "Generate codefile { output } successfully.") ;
119130 await codeFile . SerializeAsync ( writer ) ;
0 commit comments