religisaci/codeception-api-validator
该软件包最新版本(1.0.0)没有提供许可证信息。
验证 API 请求和响应是否符合 Swagger / OpenAPI 定义。此软件包是基于 awuttig/codeception-api-validator 软件包修改,适用于 PHP 7.4
1.0.0
2023-02-28 16:49 UTC
This package is auto-updated.
Last update: 2024-09-28 20:25:28 UTC
README
验证 API 请求和响应是否符合 Swagger / OpenAPI 定义
注意:这是基于 awuttig/codeception-api-validator 并修改以适用于 PHP 7.4
安装
您需要将仓库添加到您的 composer.json 文件中
composer require --dev religisaci/codeception-api-validator
用法
您可以将此模块用作其他任何 Codeception 模块,通过在您的 Codeception 套件配置中添加 'ApiValidator' 到启用模块。
启用模块并设置配置变量
schema
可以直接在配置文件中设置,也可以通过$I->haveOpenApiSchema
或$I->haveSwaggerSchema
设置
modules: enabled: - \Religisaci\ApiValidator: depends: [REST, PhpBrowser] schema: '/tests/_data/swagger.yaml'
更新 Codeception 构建
codecept build
实现 cept / cest
$I->wantToTest('Validate request and response against OpenAPI Specification.'); $I->sendGET('api/foo/bar'); $I->seeRequestIsValid(); $I->seeResponseIsValid();
方法
seeRequestIsValid()
验证当前请求是否符合当前模式定义。
$I->seeRequestIsValid();
seeResponseIsValid()
验证当前响应是否符合当前模式定义。
$I->seeRequestIsValid();
seeRequestAndResponseAreValid()
验证当前请求和响应是否符合当前模式定义。
$I->seeRequestAndResponseAreValid();
haveOpenAPISchema()
设置 OpenAPI 模式规范路径
$schema = 'file://' . codecept_root_dir('../../web/api/documentation/swagger.yaml'); $I->haveOpenAPISchema($schema);
haveSwaggerSchema()
设置 Swagger 模式规范路径
$schema = 'file://' . codecept_root_dir('../../web/api/documentation/swagger.yaml'); $I->haveSwaggerSchema($schema);
作者
- André Wuttig - 概念,初始工作 - aWuttig
- Tomáš Hojgr - 修改以适用于 PHP 7.4 - Religisaci
有关参与此项目的贡献者列表,请参阅。