awuttig/codeception-api-validator

此包的最新版本(2.0.1)没有可用的许可证信息。

根据 Swagger / OpenAPI 定义验证 API 请求和响应

2.0.1 2022-10-26 08:55 UTC

This package is auto-updated.

Last update: 2024-09-26 12:51:05 UTC


README

根据 Swagger / OpenAPI 定义验证 API 请求和响应

安装

您需要将存储库添加到您的 composer.json 文件中

    composer require --dev awuttig/codeception-api-validator

用法

您可以将此模块用作其他任何 Codeception 模块,通过将 'ApiValidator' 添加到您的 Codeception 套件配置中启用的模块。

启用模块并设置配置变量

  • schema 可以直接在配置文件中设置,也可以通过 $I->haveOpenApiSchema$I->haveSwaggerSchema 设置
modules:
    enabled:
        - ApiValidator:
            depends: REST
            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

请参阅参与此项目的贡献者列表。