Skip to content

Supported Events

Swagger Bake uses the CakePHP Event System

Event Description
SwaggerBake.Operation.created Dispatched each time an OpenAPI Path > Operation is created
SwaggerBake.Path.created Dispatched each time an OpenAPI Path is created
SwaggerBake.Schema.created Dispatched each time an OpenAPI Schema is created
SwaggerBake.initialize Dispatched during initialization phase on SwaggerBake
SwaggerBake.beforeRender Dispatched before SwaggerBake outputs OpenAPI JSON

Operation Created

The SwaggerBake.Operation.created is dispatched each time a new SwaggerBake\Lib\OpenApi\Operation is created. Here is an example of modifying a summary:

EventManager::instance()
    ->on('SwaggerBake.Operation.created', function (Event $event) {
        /** @var \SwaggerBake\Lib\OpenApi\Operation $operation */
        $operation = $event->getSubject();
        $operation->setSummary('My new summary.')
    });

Path Created

The SwaggerBake.Path.created is dispatched each time a newSwaggerBake\Lib\OpenApi\Path is created. Here is an example of modifying a summary:

EventManager::instance()
    ->on('SwaggerBake.Operation.created', function (Event $event) {
        /** @var \SwaggerBake\Lib\OpenApi\Path $path */
        $path = $event->getSubject();
        $path->setSummary('My new summary')
    });

Schema Created

The SwaggerBake.Schema.created is dispatched each time a new SwaggerBake\Lib\OpenApi\Schema instance is created. Here is an example of modifying a title:

EventManager::instance()
    ->on('SwaggerBake.Schema.created', function (Event $event) {
        /** @var \SwaggerBake\Lib\OpenApi\Schema $schema */
        $schema = $event->getSubject();
        $schema->setTitle('My new title');
    });

Initialize

The SwaggerBake.initialize is dispatched once, just before SwaggerBake\Lib\Swagger begins building OpenAPI from your routes, models, and attributes.

EventManager::instance()
    ->on('SwaggerBake.initialize', function (Event $event) {
        /** @var \SwaggerBake\Lib\Swagger $swagger */
        $swagger = $event->getSubject();
        $array = $swagger->getArray();
        $array['title'] = 'A new title';
        $swagger->setArray($array);
    });

Before Render

The SwaggerBake.beforeRender is dispatched once, just before SwaggerBake\Lib\Swagger converts data to an OpenAPI array or json.

EventManager::instance()
    ->on('SwaggerBake.beforeRender', function (Event $event) {
        /** @var \SwaggerBake\Lib\Swagger $swagger */
        $swagger = $event->getSubject();
        $array = $swagger->getArray();
        $array['title'] = 'A new title';
        $swagger->setArray($array);
    });