Validates data against a Swagger schema
composer require --dev mlambley/swagvalidator
Swagger 2.0 (aka Open API 2.0) defines the structure of your API, including end points and the structure of input and output data. See their website for more information.
If you have an existing Swagger 2.0 specification, you can use it to validate data coming in or out of your API using this tool. This library fully takes into account the features of the Swagger 2.0 specification.
None. This is a pure PHP tool with no dependencies and will work with PHP 5.6 onwards.
use Mlambley\Swagvalidator\Validator\Validator;
use Mlambley\Swagvalidator\Exception\ValidationException;
$response = $this->getApi("your/path");
$json = (string)$response->getBody();
$data = json_decode($json);
$schema = json_decode(file_get_contents(__DIR__ . '/swagger.json'));
try {
(new Validator())
->validate($schema->paths->{"your/path"}->get->responses->{"200"}->schema, $data);
} catch (ValidationException $e) {
//dd($e->getMessage());
}
Log a github issue. Your assistance is appreciated.