Validate API Requests and Responses against Swagger / OpenAPI definitions
You need to add the repository into your composer.json file
composer require --dev awuttig/codeception-api-validator
You can use this module as any other Codeception module, by adding 'ApiValidator' to the enabled modules in your Codeception suite configurations.
- The
schema
could be set in config file directly and via$I->haveOpenApiSchema
or$I->haveSwaggerSchema
modules:
enabled:
- ApiValidator:
depends: REST
schema: '/tests/_data/swagger.yaml'
Update Codeception build
codecept build
$I->wantToTest('Validate request and response against OpenAPI Specification.');
$I->sendGET('api/foo/bar');
$I->seeRequestIsValid();
$I->seeResponseIsValid();
Validates the current request against the current schema definiton.
$I->seeRequestIsValid();
Validates the current response against the current schema definiton.
$I->seeRequestIsValid();
Validates the current request and response against the current schema definiton.
$I->seeRequestAndResponseAreValid();
Set the path to the OpenAPI Schema Specification
$schema = 'file://' . codecept_root_dir('../../web/api/documentation/swagger.yaml');
$I->haveOpenAPISchema($schema);
Set the path to the Swagger Schema Specification
$schema = 'file://' . codecept_root_dir('../../web/api/documentation/swagger.yaml');
$I->haveSwaggerSchema($schema);
- André Wuttig - Concept, Initial work - aWuttig
See also the list of contributors who participated in this project.