@@ -725,6 +725,65 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
725
725
726
726
}
727
727
728
+ private void generateConfigFiles (List <File > files , Map <String , Object > bundle ) {
729
+ for (SupportingFile support : config .configFiles ()) {
730
+ try {
731
+ String outputFolder = config .outputFolder ();
732
+ if (StringUtils .isNotEmpty (support .folder )) {
733
+ outputFolder += File .separator + support .folder ;
734
+ }
735
+ File of = new File (outputFolder );
736
+ if (!of .isDirectory ()) {
737
+ of .mkdirs ();
738
+ }
739
+ String outputFilename = outputFolder + File .separator + support .destinationFilename .replace ('/' , File .separatorChar );
740
+ if (!config .shouldOverwrite (outputFilename )) {
741
+ LOGGER .info ("Skipped overwriting " + outputFilename );
742
+ continue ;
743
+ }
744
+ String templateFile ;
745
+ if ( support instanceof GlobalSupportingFile ) {
746
+ templateFile = config .getCommonTemplateDir () + File .separator + support .templateFile ;
747
+ } else {
748
+ templateFile = getFullTemplateFile (config , support .templateFile );
749
+ }
750
+
751
+ if (ignoreProcessor .allowsFile (new File (outputFilename ))) {
752
+ if (templateFile .endsWith ("mustache" )) {
753
+ String rendered = templateEngine .getRendered (templateFile , bundle );
754
+ writeToFile (outputFilename , rendered );
755
+ files .add (new File (outputFilename ));
756
+ } else {
757
+ InputStream in = null ;
758
+
759
+ try {
760
+ in = new FileInputStream (templateFile );
761
+ } catch (Exception e ) {
762
+ // continue
763
+ }
764
+ if (in == null ) {
765
+ in = this .getClass ().getClassLoader ().getResourceAsStream (getCPResourcePath (templateFile ));
766
+ }
767
+ File outputFile = new File (outputFilename );
768
+ OutputStream out = new FileOutputStream (outputFile , false );
769
+ if (in != null ) {
770
+ LOGGER .info ("writing file " + outputFile );
771
+ IOUtils .copy (in , out );
772
+ out .close ();
773
+ } else {
774
+ LOGGER .warn ("can't open " + templateFile + " for input" );
775
+ }
776
+ files .add (outputFile );
777
+ }
778
+ } else {
779
+ LOGGER .info ("Skipped generation of " + outputFilename + " due to rule in .swagger-codegen-ignore" );
780
+ }
781
+ } catch (Exception e ) {
782
+ throw new RuntimeException ("Could not generate config file '" + support + "'" , e );
783
+ }
784
+ }
785
+ }
786
+
728
787
private Map <String , Object > buildSupportFileBundle (List <Object > allOperations , List <Object > allModels ) {
729
788
730
789
Map <String , Object > bundle = new HashMap <>();
@@ -795,8 +854,9 @@ public List<File> generate() {
795
854
List <Object > allOperations = new ArrayList <>();
796
855
generateApis (files , allOperations , allModels );
797
856
798
- // supporting files
857
+ // supporting and config files
799
858
Map <String , Object > bundle = buildSupportFileBundle (allOperations , allModels );
859
+ generateConfigFiles (files , bundle );
800
860
generateSupportingFiles (files , bundle );
801
861
config .processOpenAPI (openAPI );
802
862
return files ;
@@ -840,7 +900,7 @@ public Map<String, Object> generateBundle() {
840
900
841
901
// supporting files
842
902
Map <String , Object > bundle = buildSupportFileBundle (allOperations , allModels );
843
- Json . prettyPrint ( bundle );
903
+ generateConfigFiles ( files , bundle );
844
904
generateSupportingFiles (files , bundle );
845
905
config .processOpenAPI (openAPI );
846
906
return bundle ;
0 commit comments