canvural / php-openapi-faker
Library to generate fake data for OpenAPI request/response/schemas.
Fund package maintenance!
canvural
www.paypal.me/canvural
Installs: 299 947
Dependents: 1
Suggesters: 0
Security: 0
Stars: 93
Watchers: 5
Forks: 2
Open Issues: 2
Requires
- php: ^8.0 || ^8.1 || ^8.2
- ext-json: *
- cebe/php-openapi: ^1.7
- fakerphp/faker: ^1.20
- league/openapi-psr7-validator: ^0.18
- thecodingmachine/safe: ^2.4
Requires (Dev)
- doctrine/coding-standard: ^10
- ergebnis/composer-normalize: ^2.27
- infection/infection: ^0.26
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.9
- phpstan/phpstan-phpunit: ^1
- phpunit/phpunit: ^9.5
- rector/rector: ^0.14.7
- spatie/phpunit-snapshot-assertions: ^4.2
- symfony/var-dumper: ^6
- thecodingmachine/phpstan-safe-rule: ^1.2
README
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.