ebln / guzzle-openapi-middleware
使用 league/openapi-psr7-validator 对 openapi schema 进行验证的 Guzzle 中间件
v1.0.0
2022-08-20 13:33 UTC
Requires
- php: ^7.4 || ^8.0 || ^8.1
- guzzlehttp/promises: ^1.5
- league/openapi-psr7-validator: ^0.18
- psr/http-message: ^1.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.28
- guzzlehttp/guzzle: ^7.3
- phpmd/phpmd: ^2.12
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- vimeo/psalm: ^4.26
This package is not auto-updated.
Last update: 2024-09-29 22:10:29 UTC
README
此中间件仅适配 Guzzle 使用 league/openapi-psr7-validator,请参阅他们的项目文档
安装
composer require ebln/guzzle-openapi-middleware
用法
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use League\OpenAPIValidation\PSR7\ValidatorBuilder;
$builder = new ValidatorBuilder();
// call either setSchemaFactory() or one of the from*() methods optionally add a PSR6 cache
// @see https://github.com/thephpleague/openapi-psr7-validator#readme
$middleware = new Middleware($builder->getRequestValidator(), $builder->getResponseValidator());
// @see https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware
$stack = HandlerStack::create();
$stack->push($middleware, 'openapi_validation');
$client = new Client(['handler' => $stack]);