Library to generate fake data for your OpenAPI requests, responses and schemas.
$faker = \Vural\OpenAPIFaker\OpenAPIFaker::createFromJson($yourSchemaAsJson);
$fakeData = $faker->mockResponse('/todos','GET');
You can install the package via composer:
composer require --dev canvural/php-openapi-faker
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');
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.
Overrides minItems
property if it's less than this value.
Override maxItems
if it's greater than this value.
If enabled, every property or item will be generated regardless if they are required or not. Default: false
By default, OpenAPIFaker
uses a dynamic generation strategy. You can enable the static examples generation by using the static
strategy.
Default: dynamic
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
People:
Resources:
The MIT License (MIT). Please see License File for more information.