Class luya\admin\openapi\OpenApiGenerator

Inheritanceluya\admin\openapi\OpenApiGenerator
Available since version3.2.0
Source Code https://github.com/luyadev/luya-module-admin/blob/master/src/openapi/OpenApiGenerator.php

Generate the OpenApi Instance.

Usage example of how to create a custom OpenApi file generator.

$generator = new Generator(Yii::$app->urlManager, [
    // additional not yii\web\RestRule Endpoints
    'user' => UserRestController::class,
    'groups' => GroupRestController::class,
]);

$openapi = new OpenApiGenerator($generator);

// always return as json
return $this->asJson($openapi->create()->getSerializableData());

Property Details

Hide inherited properties

$generator public property

Method Details

Hide inherited methods

__construct() public method

Constructor with Generator Object

public void __construct ( luya\admin\openapi\Generator $generator )
$generator luya\admin\openapi\Generator

                public function __construct(Generator $generator)
{
    if (!class_exists(OpenApi::class)) {
        throw new InvalidConfigException("The composer package `cebe/php-openapi` must be installed to generate the OpenAPI file.");
    }
    $this->generator = $generator;
}

            
create() public method

Create the OpenApi Instance.

public \cebe\openapi\spec\OpenApi create ( )

                public function create()
{
    return new OpenApi($this->getDefinition());
}

            
getComponents() public method

Get Components Object array

public \cebe\openapi\spec\Components getComponents ( )

                public function getComponents()
{
    return new Components([
        'securitySchemes' => [
            'BearerAuth' => new SecurityScheme([
                'type' => 'http',
                'scheme' => 'bearer',
                'bearerFormat' => 'AuthToken and JWT Format' # optional, arbitrary value for documentation purposes
            ])
        ],
    ]);
}

            
getDefinition() public method

Get base definition.

public array getDefinition ( )

                public function getDefinition()
{
    return [
        'openapi' => '3.0.2',
        'info' => $this->getInfo(),
        'paths' => $this->generator->getPaths(),
        'components' => $this->getComponents(),
        'security' => $this->getSecurity(),
        'servers' => $this->getServers(),
    ];
}

            
getInfo() public method

Get Info Object

public \cebe\openapi\spec\Info getInfo ( )

                public function getInfo()
{
    return new Info([
        'title' => Yii::$app->siteTitle,
        'version' => Yii::$app->version,
    ]);
}

            
getSecurity() public method

Get Security Array

public array getSecurity ( )

                public function getSecurity()
{
    return [
        'BearerAuth' => [],
    ];
}

            
getServers() public method

Get Servers

public array getServers ( )
return array

An array with Server objects

                public function getServers()
{
    return [
        new Server([
            'url' => Url::base(true),
            'description' => Yii::$app->siteTitle . ' Server',
        ])
    ];
}