Latest release: v0.4

Apitte\OpenApi

Content

Installation

This plugin requires Apitte/Core library.

At first you have to register the main extension.

extensions:
    api: Apitte\Core\DI\ApiExtension
1
2

Secondly, add the OpenApiPlugin plugin.

api:
    plugins:
        Apitte\OpenApi\DI\OpenApiPlugin:
1
2
3

Configuration

You can configure Swagger UI with a few optional parameters.

api:
    plugins:
        Apitte\OpenApi\DI\OpenApiPlugin:
            swagger:
                url: null # default url
                expansion: list # list|full|none
                filter: true # true|false|string
                title: My API v2
1
2
3
4
5
6
7
8

Usage

Let say you would like to display application's OpenAPI in some swagger gui. At first you have to make a controller, secondly inject the OpenApiService and create a schema.

At least send the response with generated schema.

services:
    - App\Controllers\OpenApiController
1
2
namespace App\Controllers;

use Apitte\Core\Annotation\Controller\Controller;
use Apitte\Core\Annotation\Controller\Method;
use Apitte\Core\Annotation\Controller\Path;
use Apitte\Core\Annotation\Controller\RootPath;
use Apitte\Core\Http\ApiRequest;
use Apitte\Core\Http\ApiResponse;
use Apitte\Core\UI\Controller\IController;
use Apitte\OpenApi\OpenApiService;

/**
 * @Controller
 * @RootPath("/openapi")
 */
final class OpenApiController implements IController
{

    /** @var OpenApiService @inject */
    public $openApiService;

    /**
     * @Path("/schema")
     * @Method("GET")
     */
    public function index(ApiRequest $request, ApiResponse $response): ApiResponse
    {
        $schema = $this->openApiService->createSchema();

        return $response
            ->writeJsonBody($schema->toArray())
            ->withAddedHeader('Access-Control-Allow-Origin', '*');
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

At the end, open your browser and locate to localhost/<api-project>/openapi/schema.