PHPackages                             canvural/php-openapi-faker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. canvural/php-openapi-faker

ActiveLibrary[API Development](/categories/api)

canvural/php-openapi-faker
==========================

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

2.1.0(3y ago)92395.8k↑33.8%3[2 PRs](https://github.com/canvural/php-openapi-faker/pulls)2MITPHPPHP ^8.0 || ^8.1 || ^8.2

Since Jun 15Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/canvural/php-openapi-faker)[ Packagist](https://packagist.org/packages/canvural/php-openapi-faker)[ Fund](https://www.paypal.me/canvural)[ GitHub Sponsors](https://github.com/canvural)[ RSS](/packages/canvural-php-openapi-faker/feed)WikiDiscussions 2.1.x Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (19)Used By (2)

php-openapi-faker
=================

[](#php-openapi-faker)

[![Tests](https://github.com/canvural/php-openapi-faker/workflows/Tests/badge.svg)](https://github.com/canvural/php-openapi-faker/workflows/Tests/badge.svg)[![codecov](https://camo.githubusercontent.com/4cff5689761e9313926ef2ee640d5acc9980f3dd62acd2b81a3fcc009b16caa0/68747470733a2f2f636f6465636f762e696f2f67682f63616e767572616c2f7068702d6f70656e6170692d66616b65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/canvural/php-openapi-faker)[![Infection MSI](https://camo.githubusercontent.com/1d6198d2a06bb7c531606157624cef7b1ddd3e32eba54e88d264da3e1e811611/68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f63616e767572616c2f7068702d6f70656e6170692d66616b65722f6d6173746572)](https://infection.github.io)[![PHPStan](https://camo.githubusercontent.com/d300bb2a4c15228ad2fa238fe49f1aa67ea3fb95332a246ab4303af0d3a0178e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d627269676874677265656e2e7376673f7374796c653d666c6174266c6f676f3d706870)](https://phpstan.org)

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

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

Installation
------------

[](#installation)

You can install the package via composer:

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

Usage
-----

[](#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

[](#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`

[](#minitems)

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

#### `maxItems`

[](#maxitems)

Override `maxItems` if it's greater than this value.

### `alwaysFakeOptionals`

[](#alwaysfakeoptionals)

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

### `strategy`

[](#strategy)

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

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

People:

- [Can Vural](https://github.com/canvural)
- [All Contributors](../../contributors)

Resources:

- [cebe/php-openapi](https://github.com/cebe/php-openapi)
- [league/openapi-psr7-validator](https://github.com/thephpleague/openapi-psr7-validator)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance59

Moderate activity, may be stable

Popularity48

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~131 days

Recently: every ~327 days

Total

17

Last Release

53d ago

Major Versions

0.1.5 → 1.0.02021-11-19

1.0.4 → v2.0.02022-08-23

2.1.0 → 3.0.x-dev2022-11-22

PHP version history (5 changes)0.1.0PHP ^7.4

0.1.4PHP &gt;=7.4

v2.0.0PHP ^8.0 || ^8.1

2.0.2PHP ^8.0 || ^8.1 || ^8.2

2.1.x-devPHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2f83986d283a52780c9a1e81cfc84d37cdd2e7596ccc5a748f02f2cf69d5336?d=identicon)[canvural](/maintainers/canvural)

---

Top Contributors

[![canvural](https://avatars.githubusercontent.com/u/1574232?v=4)](https://github.com/canvural "canvural (75 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (47 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (32 commits)")[![cschindl](https://avatars.githubusercontent.com/u/28109094?v=4)](https://github.com/cschindl "cschindl (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")[![LVoogd](https://avatars.githubusercontent.com/u/9071507?v=4)](https://github.com/LVoogd "LVoogd (1 commits)")[![rodrigoprimo](https://avatars.githubusercontent.com/u/77215?v=4)](https://github.com/rodrigoprimo "rodrigoprimo (1 commits)")

---

Tags

fakermockdataopenapiopenapi3php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/canvural-php-openapi-faker/health.svg)

```
[![Health](https://phpackages.com/badges/canvural-php-openapi-faker/health.svg)](https://phpackages.com/packages/canvural-php-openapi-faker)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)[ovac/idoc

Generate beautiful API documentation from your Laravel application

184477.6k2](/packages/ovac-idoc)[monicahq/laravel-sabre

Sabre DAV server adapter for Laravel.

58434.2k](/packages/monicahq-laravel-sabre)[worksome/graphlint

A static analysis tool for GraphQL

13189.4k](/packages/worksome-graphlint)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
