@@ -30,7 +30,7 @@ public function __construct()
3030 }
3131 }
3232
33- public function generatePluginDoc (string $ pluginName , string $ format = 'json ' ): string
33+ public function generatePluginDoc (string $ pluginName , string $ format = 'json ' , bool $ writeToFile = false ): string
3434 {
3535 BaseValidator::check ('plugin ' , $ pluginName , [new NotEmpty ()]);
3636 Manager::getInstance ()->checkIsPluginActivated ($ pluginName );
@@ -40,8 +40,7 @@ public function generatePluginDoc(string $pluginName, string $format = 'json'):
4040
4141 // Check if the API class has been annotated and use the generated annotations file if it hasn't
4242 $ pluginAnnotationsSource = $ pluginDir . '/API.php ' ;
43- $ tempGenerator = new Generator (StaticContainer::get (NullLogger::class));
44- $ openapi = $ tempGenerator ->generate ([
43+ $ openapi = (new Generator (StaticContainer::get (NullLogger::class)))->generate ([
4544 $ pluginAnnotationsSource ,
4645 ]);
4746 if (trim ($ openapi ->toYaml ()) === 'openapi: ' . OpenApi::DEFAULT_VERSION ) {
@@ -62,8 +61,15 @@ public function generatePluginDoc(string $pluginName, string $format = 'json'):
6261 $ pluginAnnotationsSource ,
6362 ]);
6463
64+ // Update title with plugin name
6565 $ openapi ->info ->title .= ' for ' . $ pluginName . ' plugin ' ;
6666
67+ // Remove the current server so that it isn't used when saving the spec file. It should only leave demo
68+ if ($ writeToFile && is_array ($ openapi ->servers ) && count ($ openapi ->servers ) > 1 ) {
69+ unset($ openapi ->servers [0 ]);
70+ $ openapi ->servers = array_values ($ openapi ->servers );
71+ }
72+
6773 return strtolower ($ format ) === 'yaml ' ? $ openapi ->toYaml () : $ openapi ->toJson ();
6874 }
6975}
0 commit comments