ebln / guzzle-openapi-middleware

使用 league/openapi-psr7-validator 对 openapi schema 进行验证的 Guzzle 中间件

v1.0.0 2022-08-20 13:33 UTC

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]);