@@ -34,17 +34,29 @@ class GenerateServerVersion extends Command {
3434 */
3535 private $ tempDir ;
3636
37+ /**
38+ * @var boolean
39+ */
40+ private $ onlyEnumsMode ;
41+
3742 /**
3843 * @var string
3944 */
4045 private $ destinationDir ;
4146
47+ /**
48+ * @var string
49+ */
50+ private $ templateDir ;
51+
4252 public function __construct ()
4353 {
4454 parent ::__construct ();
4555
4656 $ this ->tempDir = config ('openapi-server-generator.temp_dir ' , config ('openapi-server-generator.output_dir ' ));
4757 $ this ->destinationDir = config ('openapi-server-generator.destination_dir ' , config ('openapi-server-generator.app_dir ' ));
58+ $ this ->templateDir = config ("openapi-server-generator.template_dir " , '' );
59+ $ this ->onlyEnumsMode = config ('openapi-server-generator.only_enums_mode ' , false );
4860 }
4961
5062 /**
@@ -75,7 +87,11 @@ private function generateDto(): void
7587
7688 $ command = "$ bin generate -i $ inputFile -g php -p 'invokerPackage= $ invokerPackage,modelPackage= $ modelPackage' -o $ this ->tempDir " ;
7789
78- $ this ->info ("Execute command: $ command " );
90+ if ($ this ->templateDir ) {
91+ $ command .= " -t " . escapeshellarg ($ this ->templateDir );
92+ }
93+
94+ $ this ->info ("Executing command: $ command " );
7995
8096 shell_exec ($ command );
8197 }
@@ -102,9 +118,14 @@ private function clearAppDir(): void {
102118
103119 private function copyDto (): void
104120 {
105- shell_exec ("cp -rf $ this ->tempDir /lib/Dto " . $ this ->getAppPathToDto ());
106- shell_exec ("cp -f $ this ->tempDir /lib/Configuration.php " . $ this ->getAppPathToDto ());
107- shell_exec ("cp -n $ this ->tempDir /lib/ObjectSerializer.php " . $ this ->getAppPathToDto ());
121+ if ($ this ->onlyEnumsMode ) {
122+ $ modelsPath = $ this ->getAppPathToModels ();
123+ shell_exec ("find $ this ->tempDir /lib/Dto -name \*Enum.php -exec cp {} $ modelsPath \; " );
124+ } else {
125+ shell_exec ("cp -rf $ this ->tempDir /lib/Dto " . $ this ->getAppPathToDto ());
126+ shell_exec ("cp -f $ this ->tempDir /lib/Configuration.php " . $ this ->getAppPathToDto ());
127+ shell_exec ("cp -n $ this ->tempDir /lib/ObjectSerializer.php " . $ this ->getAppPathToDto ());
128+ }
108129 }
109130
110131 private function removeGeneratedDto (): void
@@ -138,7 +159,12 @@ private function patchSerializer(): void
138159 {
139160 $ file = $ this ->getAppPathToDto () . DIRECTORY_SEPARATOR . 'ObjectSerializer.php ' ;
140161
141- $ this ->info ("Patch serializer: $ file " );
162+ if (!file_exists ($ file )) {
163+ $ this ->info ("Skipping serializer patching, no such file: $ file " );
164+ return ;
165+ }
166+
167+ $ this ->info ("Patching serializer: $ file " );
142168
143169 $ patcher = new SerializerPatcher ($ file );
144170
0 commit comments