Symfony 2 bundle for leveraging swagger development & testing tools
composer require epfremme/swagger-bundlecomposer installNote: This bundle should only be used in dev mode and be included as a dev only dependency. The purpose of these resources are to assist the creation of an API symfony application during development
There are 2 main bundle parameters to you can override in your parameters.yml:
swagger_bundle.swagger_file default: Resources/docs/swagger.yaml - specify swagger fileswagger_bundle.mock_api default: true - turn on/off to deactivate the mock API listenerMore deatils on each below...
Behat documentation: behat
Sample Behat configuration using the SwaggerContext for validating json schemas
default:
suites:
app:
paths:
- %paths.base%/src/AppBundle/Tests/Features/
contexts:
- Epfremme\SwaggerBundle\Behat\SwaggerContext: ~
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
testers:
rerun_cache: .behat_rerun_cache
Takes in a TableNode for key value pairs to be used as request payload
Format: | key | value |
Make a request to the API with or without a request method (defaults to GET)
Store a swagger definition schema from your swagger doc to be used to validate API json response data
Note: The swagger documentation used is the file defined in the swagger_bundle.swagger_file parameter
Store a swagger response schema from your swagger doc to be used to validate API json response data
Note: The swagger documentation used is the file defined in the swagger_bundle.swagger_file parameter
Assert the the response is json
Assert that the response json contains "key"
Assert the response json key equals "value"
Validates the response data agains the previously specified swagger definition or response schema
The mock API can be disabled by setting swagger_bundle.mock_api to false. Also note the listener will not run in
prod mode if you forget to move it to require-dev or added it to the wrong are of your kernel
app/console swagger:install:mock-apix-mock-api header to the request to trigger the listener to trigger the mock responseA useful chrome extension used to mock request headers Modheader
Additional chance methods & options that can be defined in the swagger.json doc chance
How can I help you explore Laravel packages today?