定制 canvural/php-openapi-faker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

canvural/php-openapi-faker

最新稳定版本:2.1.0

Composer 安装命令:

composer require canvural/php-openapi-faker

包简介

Library to generate fake data for OpenAPI request/response/schemas.

README 文档

README

Tests codecov Infection MSI PHPStan

Library to generate fake data for your OpenAPI requests, responses and schemas.

$faker = \Vural\OpenAPIFaker\OpenAPIFaker::createFromJson($yourSchemaAsJson);
$fakeData = $faker->mockResponse('/todos','GET');

Installation

You can install the package via composer:

composer require --dev canvural/php-openapi-faker

Usage

First you need to create an instance of OpenAPIFaker with your schema that you want to fake data from. You can use createFromJson, createFromYaml or createFromSchema to create an instance of OpenAPIFaker.

$faker = \Vural\OpenAPIFaker\OpenAPIFaker::createFromJson($yourSchemaAsJson);

Then you can use mockResponse, mockResponseForExample, mockRequest, mockRequestForExample, mockComponentSchema and mockComponentSchemaForExample methods on it to generate fake data for your requests, responses and schemas. Like so:

$fakeData = $faker->mockResponse('/todos','GET');

Options

There are some options you can use to modify some behaviour. You can pass options as an associative array to setOptions method in OpenAPIFaker. For example:

$faker = \Vural\OpenAPIFaker\OpenAPIFaker::createFromJson($yourSchemaAsJson)
    ->setOptions(['minItems' => 5]);

Below you can find explanation for each option.

minItems

Overrides minItems property if it's less than this value.

maxItems

Override maxItems if it's greater than this value.

alwaysFakeOptionals

If enabled, every property or item will be generated regardless if they are required or not. Default: false

strategy

By default, OpenAPIFaker uses a dynamic generation strategy. You can enable the static examples generation by using the static strategy. Default: dynamic

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

People:

Resources:

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 386.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 93
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 93
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-14