mlambley / swagfaker
Create fake data from a Swagger schema
Installs: 6 395
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 4
Requires
- fzaninotto/faker: ^1.7
Requires (Dev)
- codeception/aspect-mock: ^3.0
- friendsofphp/php-cs-fixer: ^2.12
- mlambley/swagception: ^1.0
This package is auto-updated.
Last update: 2024-11-21 22:30:58 UTC
README
Generates fake data which will validate against your Swagger 2.0 schema.
How to install
composer require mlambley/swagfaker:^1.0
What is Swagger?
Swagger 2.0 (aka Open API 2.0) defines the structure of your API, including end points and the structure of input and output data. See their website for more information.
What is Swagfaker?
Swagfaker allows you to generate fake data based upon your existing Swagger 2.0 specification. You can use it to generate data to be sent to your API during acceptance testing.
Example
Let's say your Swagger schema looks like this:
{ "type": "object", "required": [ "Name", "DateOfBirth", "Identifier", "VisitCount" ], "properties": { "Name": { "type": "string" }, "DateOfBirth": { "type": "string", "format": "date" }, "Identifier": { "type": "string", "pattern": "^[0-9]{3}-[0-9]{4}$" }, "VisitCount": { "type": "integer", "minimum": 0 } } }
Then generate fake data using:
$values = (new \SwaggerFaker\Faker())->generate($schema);
Your values now might look like this:
object(stdClass) {
"Name" => "Quod."
"DateOfBirth" => "1971-08-20"
"Identifier" => "037-1259"
"VisitCount" => 1463093889
}
Issues?
Log a github issue. Your assistance is appreciated.
Credit
Give some love to Leko for their JSON Schema Faker which this library was originally copied from.