Download the PHP package alexcicioc/swagger-router without Composer
On this page you can find all versions of the php package alexcicioc/swagger-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexcicioc/swagger-router
More information about alexcicioc/swagger-router
Files in alexcicioc/swagger-router
Package swagger-router
Short Description Handles routing and request/response validation as defined in an OpenApi spec
License MIT
Informations about the package swagger-router
swagger-router
Swagger Router is a library that speeds up API development while having it documented.
It uses a json spec file compatible with OpenAPI specification 2.0 and should support most of the features but if you find something missing feel free to open a pull request or an issue.
Install via composer:
composer require alexcicioc/swagger-router
Using swagger-router to bootstrap the API:
Defining the endpoints using swagger
You'll need to define your API endpoints in the swagger spec. Here's a simple example you can use (it's in yaml for readability but should be converted to json):
Recommendation: You can use Swagger Editor to safely modify the spec then click on the File menu and "Convert and save to JSON".
Redirecting the requests
You'll need to redirect everything to index.php. If you're using apache you can add this to your .htaccess file
Bootstrapping the app using swagger-router
In index.php you'll have to build the SwaggerRouter instance. You can use this sample:
Creating a controller
Previously in the spec we added these lines:
This tells swagger-router to search for the Courses
controller and call the method getCourses
Sample spec:
https://github.com/alexcicioc/swagger-router/blob/master/sample-spec.json
Laravel compatibility
Swagger Router's middlewares are not compatible with Laravel's yet, however there's a workaround this.
Here's a sample Laravel middleware that calls the swagger router (not properly tested, may have some side effects):
All versions of swagger-router with dependencies
guzzlehttp/psr7 Version ^1.5
league/oauth2-server Version ^7.4
ext-json Version *