Class luya\admin\openapi\OpenApiGenerator
| Inheritance | luya\admin\openapi\OpenApiGenerator |
|---|---|
| Available since version | 3.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());
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $generator | luya\admin\openapi\Generator | luya\admin\openapi\OpenApiGenerator |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Constructor with Generator Object | luya\admin\openapi\OpenApiGenerator |
| create() | Create the OpenApi Instance. | luya\admin\openapi\OpenApiGenerator |
| getComponents() | Get Components Object array | luya\admin\openapi\OpenApiGenerator |
| getDefinition() | Get base definition. | luya\admin\openapi\OpenApiGenerator |
| getInfo() | Get Info Object | luya\admin\openapi\OpenApiGenerator |
| getSecurity() | Get Security Array | luya\admin\openapi\OpenApiGenerator |
| getServers() | Get Servers | luya\admin\openapi\OpenApiGenerator |
Property Details
Method Details
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 the OpenApi Instance.
| public \cebe\openapi\spec\OpenApi create ( ) |
public function create()
{
return new OpenApi($this->getDefinition());
}
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
])
],
]);
}
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(),
];
}
Get Info Object
| public \cebe\openapi\spec\Info getInfo ( ) |
public function getInfo()
{
return new Info([
'title' => Yii::$app->siteTitle,
'version' => Yii::$app->version,
]);
}
Get Security Array
| public array getSecurity ( ) |
public function getSecurity()
{
return [
'BearerAuth' => [],
];
}
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',
])
];
}