Skip to content

Commit

Permalink
Merge pull request #199 from cnizzardini/feature/198-before-render-event
Browse files Browse the repository at this point in the history
Add SwaggerBake.beforeRender event #198
  • Loading branch information
cnizzardini authored Oct 3, 2020
2 parents b3983c1 + 2233f91 commit 9c9c0d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Lib/Extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Lib/Swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9c9c0d7

Please sign in to comment.