diff --git a/src/Lib/Extension/README.md b/src/Lib/Extension/README.md index 0a0f3342..a2e74a47 100644 --- a/src/Lib/Extension/README.md +++ b/src/Lib/Extension/README.md @@ -26,6 +26,16 @@ EventManager::instance() }); ``` +The `SwaggerBake.beforeRender` is dispatched once, just before SwaggerBake converts +data to an OpenAPI array or json. + +```php +EventManager::instance() + ->on('SwaggerBake.beforeRender', function (Event $event) { + // your code + }); +``` + ## Adding your Extension to the SwaggerBake project 1. Your extension must implement ExtensionInterface. Read the interfaces comments and refer to the CakeSearch diff --git a/src/Lib/Swagger.php b/src/Lib/Swagger.php index 35a444f5..781f5fce 100644 --- a/src/Lib/Swagger.php +++ b/src/Lib/Swagger.php @@ -3,6 +3,8 @@ namespace SwaggerBake\Lib; +use Cake\Event\Event; +use Cake\Event\EventManager; use Cake\Utility\Inflector; use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; @@ -72,6 +74,10 @@ public function __construct(EntityScanner $entityScanner) */ public function getArray(): array { + EventManager::instance()->dispatch( + new Event('SwaggerBake.beforeRender', $this->array) + ); + foreach ($this->array['paths'] as $method => $paths) { foreach ($paths as $pathId => $path) { if ($path instanceof Path) {