PHP code example of iadvize / php-swaggerize-fastroute-library
1. Go to this page and download the library: Download iadvize/php-swaggerize-fastroute-library library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iadvize / php-swaggerize-fastroute-library example snippets
nOperationParser = new \Iadvize\SwaggerizeFastRoute\OperationParser\LumenControllerOperationParser('Controllers\\Namespace\\');
$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r, ['cacheFile' => 'route/file/path']) {
\Iadvize\SwaggerizeFastRoute\addRoutes(
'path/to/swagger/json',
$r,
$lumenOperationParser,
['routeFile' => 'path/to/generated/route/file', 'cacheEnabled' => false]
);
});
// Fetch method and URI from somewhere
// ... see FastRoute Dispatcher
namespace My\Application;
use Laravel\Lumen\Application as LumenApplication;
/**
* Class Application
*
* @package My\Application
*/
class Application extends LumenApplication
{
/**
* {@inheritdoc}
*/
protected function createDispatcher()
{
return $this->dispatcher ?: \FastRoute\simpleDispatcher(function ($r) {
foreach ($this->routes as $route) {
$r->addRoute($route['method'], $route['uri'], $route['action']);
}
$operationParser = new \Iadvize\SwaggerizeFastRoute\OperationParser\LumenControllerOperationParser('My\Application\Http\Controllers');
\Iadvize\SwaggerizeFastRoute\addRoutes(storage_path('docs/definition.json'), $r, $operationParser, ['routeFile' => 'route/file/path']);
});
}
}
composer
JSON
{
// ...
"paths": {
"/pets": {
"get": {
// ...
}
"put": {
// ...
}
}
"/store": {
"post": {
// ...
}
}
}
// ...
}