PHP code example of eru123 / swagger
1. Go to this page and download the library: Download eru123/swagger 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/ */
eru123 / swagger example snippets
// Include the vendor/autoload.php file.
gger\Swagger;
use eru123\router\Router;
// Define Swagger path and it's json file path.
$swagger = Swagger::build([
'/docs' => [
'/v1' => __DIR__ . '/swaggerv1.json',
'/v2' => __DIR__ . '/swaggerv2.json',
'/v3' => [
'-dev' => __DIR__ . '/swaggerv3-dev.json',
'-prod' => __DIR__ . '/swaggerv3-prod.json',
]
]
]);
// Create a new Router instance for the API path and add the Swagger instance as a child.
$api = new Router();
$api->base('/api');
$api->child($swagger);
// Create the main Router instance
$router = new Router();
// Add a fallback route to return a 404 json response.
$router->fallback('/', function () {
return [
'error' => '404 Not Found'
];
});
// Add the API router as a child of the main router.
$router->child($api);
// Run the router.
$router->run();