This bundle integrates Swagger in Symfony.
Currently, it supports the following features:
- Automatic validation of all incoming requests based on the Swagger definition (including headers and query string)
- Configuring multiple API with different swagger files using configuration
- FOSRestBundle integration: automatic configuration of the ParamFetcher
- Behat integration: context to validate the response
Add the required package using composer.
composer require nicofuma/swagger-bundle:^1.0
composer require nicofuma/swagger-bundle:@dev
Add the bundle to your AppKernel.
// in %kernel.root_dir%/AppKernel.php
$bundles = array(
// ...
new Nicofuma\SwaggerBundle\NicofumaSwaggerBundle(),
// ...
);
nicofuma_swagger:
definition:
pattern: '/api/v1'
swagger_file: swagger/swagger.json
strict: true
pattern
any url matching this pattern will be tested against the swagger_file
swagger_file
swagger file to use for this API. Can be either an bsolute path, a path relative to %kernel.root_dir%/Resources/
or a bundle resource @MyBundle/Dir/swagger.json
strict
whether or not an exception must be thrown if the path does not match any definition in the swagger file
# Default configuration for extension with alias: "swagger"
nicofuma_swagger:
definitions:
-
pattern:
# use the urldecoded format
path: ^/api/public/
host: null
ips: []
methods: []
swagger_file: swagger-public.json
strict: true
-
pattern:
# use the urldecoded format
path: ^/api/private/
host: null
ips: []
methods: []
swagger_file: swagger-private.json
strict: true
Add the following context in your behat.yml file
- Nicofuma\SwaggerBundle\Tests\Behat\Context\SwaggerContext: {map: '@swagger.validator_map'}
NicofumaSwaggerBundle is an open source project. If you'd like to contribute, please do.
This library is under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.