Download the PHP package gertjuhh/symfony-openapi-validator without Composer
On this page you can find all versions of the php package gertjuhh/symfony-openapi-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gertjuhh/symfony-openapi-validator
More information about gertjuhh/symfony-openapi-validator
Files in gertjuhh/symfony-openapi-validator
Package symfony-openapi-validator
Short Description OpenAPI validator for Symfony application tests
License MIT
Informations about the package symfony-openapi-validator
OpenAPI validation for Symfony application tests
This package can validate requests made in application tests, based of Symfony's WebTestCase
, against OpenAPI
specifications. This is done by converting HttpFoundation
objects using the
PSR-7 Bridge and passing them to the
OpenAPI PSR-7 Message Validator.
Installation
Usage
- Add the
OpenApiValidator
trait to yourWebTestCase
- Create a client by calling
self::createClient()
- Alternatively use your own custom logic creating an instance of
KernelBrowser
- Alternatively use your own custom logic creating an instance of
- Execute the request you wish to validate using the client
- Call
self::assertOpenApiSchema(<schema>, <client>);
schema
: path to corresponding OpenAPI yaml schemaclient
: the client used to make the request
- Or optionally use the
self::assertResponseAgainstOpenApiSchema(<schema>, <client>);
to only validate the response- The
operationAddress
can be passed as a third argument for this function but by default it will retrieve the operation from theclient
.
- The
Setting up a cache
The underlying library can use a PSR-6 cache. This provides a significant speedup when running multiple tests against a single schema, since it can be parsed once and reused.
In order to activate this cache, you can pass a PSR-6 cache instance to the static property
\Gertjuhh\SymfonyOpenapiValidator\StaticOpenApiValidatorCache::$validatorCache
. For example:
Setting storeSerialized
to false on the ArrayAdapter instance is recommended as it lowers memory usage by storing the actual objects;
otherwise, Symfony will store a serialized representation of the OpenAPI schema and deserialize it on every test run.
This snippet can be embedded in a bootstrap script for PHPUnit.
Example
All versions of symfony-openapi-validator with dependencies
league/openapi-psr7-validator Version ^0.22
nyholm/psr7 Version ^1.5
symfony/browser-kit Version ^5.4 || ^6.0 || ^7.0
symfony/framework-bundle Version ^5.4 || ^6.0 || ^7.0
symfony/psr-http-message-bridge Version ^2.1 || ^6.0 || ^7.0