Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.26 KB

SWAGGER.md

File metadata and controls

42 lines (31 loc) · 1.26 KB

Swagger Integration

You can use Swagger for document your RESTful API. Rest Daemon project use zircote/swagger-php implementation of annotations.

In Your Code

Use in Runtime

<?php
$generator = new \FreeElephants\RestDaemon\Integration\Swagger\RouterGenerator();
$routerConfig = $generator->getRouterConfig($directoryForScanning);

# and use as RestServer router configuration
$server = (new \FreeElephants\RestDaemon\RestServerBuilder())->buildServer($routerConfig);
$server->run();

Use with File Caching

<?php

const ROUTES_FILENAME = 'router.php';

if(file_exists(ROUTES_FILENAME)) {
    $routerConfig = require ROUTES_FILENAME;
} else {
    $generator = new \FreeElephants\RestDaemon\Integration\Swagger\RouterGenerator();    
    $routerConfig = $generator->getRouterConfig($directoryForScanning);
    $output = sprintf('<?php
    return %s;
    ', var_export($routerConfig, true));
    file_put_contents(ROUTES_FILENAME, $output);
}

$server = (new \FreeElephants\RestDaemon\RestServerBuilder())->buildServer($routerConfig);
$server->run();

CLI Tool

Use vendor/bin/rest-daemon generate:routes:swagger to generate routing configuration from annotations in your sources.