basster / silex-simple-swagger-provider
A silex service provider that integrates swagger-php 2.0 into silex
Installs: 71 434
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- php: >=5.4
- silex/silex: ^2.0
- zircote/swagger-php: ^2.0
Requires (Dev)
- phpunit/phpunit: ^4.5 || ^5.3
This package is auto-updated.
Last update: 2024-11-22 06:39:33 UTC
README
silex-simple-swagger-provider is a silex service provider that integrates swagger-php (Version 2) into silex. This service provider adds routes for generating and exposing a swagger defintion based on swagger-php annotations. The swagger definition can then be used with swagger-ui.
This library is strongly inspired by Jason Desrosiers silex-swagger-provider but fully rewritten to meet the needs of swagger-php (Version 2)
Installation for Silex 2
Install the silex-swagger-provider using composer.
composer require basster/silex-simple-swagger-provider:^2.0
Parameters
- swagger.servicePath: The path to the classes that contain your swagger annotations.
- swagger.excludePath: A string path or an array of paths to be excluded when generating annotations.
- swagger.apiDocPath: The URI that will be used to access the swagger definition. Defaults to
/api/api-docs
. - swagger.cache: An array of caching options that will be passed to Symfony 2's
Response::setCache
method.
Services
- swagger: An instance of
Swagger\Annotations\Swagger
. It's the already parsed swagger annotation tree.
Registering
$app->register(new Basster\Silex\Provider\Swagger\SwaggerProvider(), [ "swagger.servicePath" => __DIR__ . "/path/to/your/api", ]);
Usage
The following routes are made available by default
GET /api/api-docs
: Get the list of resources
The results of the swagger definition file is not cached internally. Instead, the routes that are created are designed
to work with an HTTP cache such as a browser cache or reverse proxy. You can configure how you want to your service
cached using the swagger.cache
parameter. By default, no caching will be done. Read about
HTTP caching in Symfony for more information about how to
customize caching behavior. The following example will allow the service definition file to be cached for 5 days.
$app["swagger.cache"] = [ "max_age": "432000", // 5 days in seconds "s_maxage": "432000", // 5 days in seconds "public": true, ]