wolfpack-it/yii2-swagger

Swagger for Yii2, extension of light/yii2-swagger.

v1.0.0 2020-04-22 07:31 UTC

This package is auto-updated.

Last update: 2024-12-22 18:31:32 UTC


README

This extension provides Swagger actions for the Yii2 Framework.

It is an extension of light/yii2-swagger.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require wolfpack-it/yii2-swagger

or add

"wolfpack-it/yii2-swagger": "^<latest version>"

to the require section of your composer.json file.

If Swagger PHP version 3 or higher is desired, also install:

"zircote/swagger-php": "<latest version> as 2.0.0",

Usage

Use the package by extending the \WolfpackIT\swagger\controllers\SwaggerController in the application where you need it. Override the init function to set the scan directories:

public function init()
{
    $this->scanDirs = [
         \Yii::getAlias('@api/models'),
         \Yii::getAlias('@api/controllers'),
    ];
    parent::init;
}

You need to add the following to the application params:

    'swagger' => [
        'oAuthConfiguration' => [
            'baseUrl' => 'https://example.com/oauth/', // must end with a / (forward slash)
            'securityScheme' => 'exampleSecurity', // will be used to auto login
            'username' => 'info@example.nl', // will be used to auto login
            'password' => 'example', // will be used to auto login
            'clientId' => 'example-client', // will be used to auto login
            'clientSecret' => 'example', // will be used to auto login
        ]
    ]

It is advised to only use the auto login functionality when the application is not in production!

If you need more granular control, look at how the actions are configured in \WolfpackIT\swagger\controllers\SwaggerController.

The rest of the documentation can be found at light/yii2-swagger.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.