Skip to content

Latest commit

 

History

History

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Readme.md

Specs

Collection of code/annotation examples and their corresponding OpenAPI specs generated using swagger-php.

Custom augmenters

Augmenters enrich the specification in spec and hybrid mode. Writing a custom augmenter is the way to extend that pipeline.

An augmenter implements PipeInterface: group() names the phase it runs in, and __invoke() receives the Specification:

<?php
...
use OpenApi\Augmenter\Group;
use OpenApi\Utils\PipeInterface;
...

class MyCustomAugmenter implements PipeInterface
{
    public function group(): string|\BackedEnum
    {
        return Group::Augment;
    }

    public function __invoke(mixed $payload): mixed
    {
        // custom augmenting

        return $payload;
    }
}

It is added with Builder::withAugmenters(). Each example has a scan.php doing that, and the yaml it generates.

Custom processors

Warning

Processors are part of the classic pipeline, which is deprecated in 7.0 and removed in 8.0. The augmenter examples above do the same in spec and hybrid mode.

Processors implement the various steps involved in converting the annotations collected into an OpenAPI spec.

Writing a custom processor is the way to extend the classic pipeline.

Processors are expected to implement the __invoke() method expecting the current Analysis object as single parameter:

<?php
...
use OpenApi\Analysis;
...

class MyCustomProcessor
{
    public function __invoke(Analysis $analysis)
    {
        // custom processing
    }
}