{"id":14063327,"url":"https://github.com/ybelenko/openapi-data-mocker","last_synced_at":"2025-04-11T21:31:05.683Z","repository":{"id":52235691,"uuid":"253581764","full_name":"ybelenko/openapi-data-mocker","owner":"ybelenko","description":"Library that generates fake data from OpenAPI 3.0 Spec","archived":false,"fork":false,"pushed_at":"2022-03-21T19:47:57.000Z","size":125,"stargazers_count":9,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T03:34:18.915Z","etag":null,"topics":["data","fake","faker","mock","mocker","oas","oas3","openapi","swagger"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ybelenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-06T18:24:20.000Z","updated_at":"2024-08-26T17:55:26.000Z","dependencies_parsed_at":"2022-08-25T00:50:41.516Z","dependency_job_id":null,"html_url":"https://github.com/ybelenko/openapi-data-mocker","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybelenko%2Fopenapi-data-mocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybelenko%2Fopenapi-data-mocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybelenko%2Fopenapi-data-mocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybelenko%2Fopenapi-data-mocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ybelenko","download_url":"https://codeload.github.com/ybelenko/openapi-data-mocker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248482886,"owners_count":21111400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","fake","faker","mock","mocker","oas","oas3","openapi","swagger"],"created_at":"2024-08-13T07:03:16.556Z","updated_at":"2025-04-11T21:31:05.412Z","avatar_url":"https://github.com/ybelenko.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Openapi Data Mocker\n\n[![Latest Stable Version](https://poser.pugx.org/ybelenko/openapi-data-mocker/v/stable)](https://packagist.org/packages/ybelenko/openapi-data-mocker)\n[![Build Status](https://github.com/ybelenko/openapi-data-mocker/actions/workflows/ci.yml/badge.svg)](https://github.com/ybelenko/openapi-data-mocker/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ybelenko/openapi-data-mocker/badge.svg?branch=master)](https://coveralls.io/github/ybelenko/openapi-data-mocker?branch=master)\n[![License](https://poser.pugx.org/ybelenko/openapi-data-mocker/license)](https://packagist.org/packages/ybelenko/openapi-data-mocker)\n\nOpenapi Data Mocker helps to generate fake data from OpenAPI 3.0 documents. Most of the methods may work with 2.0 version(fka Swagger 2.0), but it's not tested. This package was an enhancement of PHP Slim4 server in [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) project, but it easier to maintain it in separated repo.\n\n## Requirements\n- PHP ^7.3\n\n__Important notice! While PHP 8.0 declared in composer.json this package hasn't been tested against it.__\n\n## Installation via Composer\n\nRun in terminal:\n```console\ncomposer require ybelenko/openapi-data-mocker\n```\n\n## Usage example\n\nImagine we have [OpenAPI Specification 3.0.3 - Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schema-object) like this:\n```yaml\ndescription: Real world example schema\ntype: object\nproperties:\n  id:\n    type: integer\n    format: int32\n    minimum: 1\n  purchased_items:\n    type: array\n    items:\n      type: object\n      properties:\n        SKU:\n          type: string\n          format: uuid\n          maxLength: 20\n        quantity:\n          type: integer\n          format: int32\n          minimum: 1\n          maximum: 5\n        price:\n          type: object\n          properties:\n            currency:\n              type: string\n              minLength: 3\n              maxLength: 3\n              enum:\n              - USD\n              - EUR\n              - RUB\n            value:\n              type: number\n              format: float\n              minimum: 0.01\n              maximum: 99.99\n        manufacturer:\n          type: object\n          properties:\n            name:\n              type: string\n              maxLength: 30\n            country:\n              type: string\n              enum:\n              - CHN\n              - USA\n              - RUS\n  buyer:\n    type: object\n    properties:\n      first_name:\n        type: string\n        minLength: 3\n        maxLength: 15\n      last_name:\n        type: string\n        minLength: 3\n        maxLength: 15\n      credit_card:\n        type: integer\n        minimum: 1000000000000000\n        maximum: 10000000000000000\n      phone:\n        type: integer\n        minimum: 10000000000000\n        maximum: 99999999999999\n      email:\n        type: string\n        format: email\n  status:\n    type: string\n    enum:\n    - registered\n    - paid\n    - shipped\n    - delivered\n    default: registered\n  created_at:\n    type: string\n    format: date-time\n```\n\u003e Notice! While schema object presented in YAML format this library doesn't support YAML or JSON parsing right now. It means that `mockSchemaObject` method expects already decoded JSON value as argument.\n\nWhen we mock mentioned schema with `mockSchemaObject` method:\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse OpenAPIServer\\Mock\\OpenApiDataMocker as Mocker;\n$mocker = new Mocker();\n// set model classes namespace for $ref handling\n// current example doesn't use $refs in schemas, however\n$mocker-\u003esetModelsNamespace('JohnDoesPackage\\\\Model\\\\');\n// class InvoiceTest contains schema mentioned previously\n// it returns that schema with getOpenApiSchema() method declared in OpenAPIServer\\Mock\\BaseModel parent class\n$schema = \\OpenAPIServer\\Mock\\Model\\InvoiceTest::getOpenApiSchema();\n$data = $mocker-\u003emockSchemaObject($schema);\necho json_encode($data, \\JSON_PRETTY_PRINT);\n```\n\nthe output looks like:\n```json\n{\n    \"id\": 1912777939,\n    \"purchased_items\": [\n        {\n            \"SKU\": \"5ee78cfde9f05\",\n            \"quantity\": 4,\n            \"price\": {\n                \"currency\": \"EUR\",\n                \"value\": 57.635\n            },\n            \"manufacturer\": {\n                \"name\": \"Lorem i\",\n                \"country\": \"USA\"\n            }\n        }\n    ],\n    \"buyer\": {\n        \"first_name\": \"Lorem ipsum do\",\n        \"last_name\": \"Lorem ipsum \",\n        \"credit_card\": 2455087473915908,\n        \"phone\": 65526260517693,\n        \"email\": \"jfkennedy@example.com\"\n    },\n    \"status\": \"delivered\",\n    \"created_at\": \"1978-08-08T04:03:09+00:00\"\n}\n```\nOf course that output will be slightly different on every call. That's what mocker package has been developed for.\n\nYou can check extended example at [examples/extended_example.php](examples/extended_example.php).\n\n## Supported features\n\nAll data types supported except specific string formats: `email`, `uuid`, `password` which are poorly implemented.\n\n### Data Types Support\n\n| Data Type | Data Format |      Supported     |\n|:---------:|:-----------:|:------------------:|\n| `integer` | `int32`     | :white_check_mark: |\n| `integer` | `int64`     | :white_check_mark: |\n| `number`  | `float`     | :white_check_mark: |\n| `number`  | `double`    |                    |\n| `string`  | `byte`      | :white_check_mark: |\n| `string`  | `binary`    | :white_check_mark: |\n| `boolean` |             | :white_check_mark: |\n| `string`  | `date`      | :white_check_mark: |\n| `string`  | `date-time` | :white_check_mark: |\n| `string`  | `password`  | :white_check_mark: |\n| `string`  | `email`     | :white_check_mark: |\n| `string`  | `uuid`      | :white_check_mark: |\n\n### Data Options Support\n\n| Data Type   |         Option         |      Supported     |\n|:-----------:|:----------------------:|:------------------:|\n| `string`    | `minLength`            | :white_check_mark: |\n| `string`    | `maxLength`            | :white_check_mark: |\n| `string`    | `enum`                 | :white_check_mark: |\n| `string`    | `pattern`              |                    |\n| `integer`   | `minimum`              | :white_check_mark: |\n| `integer`   | `maximum`              | :white_check_mark: |\n| `integer`   | `exclusiveMinimum`     | :white_check_mark: |\n| `integer`   | `exclusiveMaximum`     | :white_check_mark: |\n| `number`    | `minimum`              | :white_check_mark: |\n| `number`    | `maximum`              | :white_check_mark: |\n| `number`    | `exclusiveMinimum`     | :white_check_mark: |\n| `number`    | `exclusiveMaximum`     | :white_check_mark: |\n| `array`     | `items`                | :white_check_mark: |\n| `array`     | `additionalItems`      |                    |\n| `array`     | `minItems`             | :white_check_mark: |\n| `array`     | `maxItems`             | :white_check_mark: |\n| `array`     | `uniqueItems`          |                    |\n| `object`    | `properties`           | :white_check_mark: |\n| `object`    | `maxProperties`        |                    |\n| `object`    | `minProperties`        |                    |\n| `object`    | `patternProperties`    |                    |\n| `object`    | `additionalProperties` |                    |\n| `object`    | `required`             |                    |\n| `*`         | `$ref`                 | :white_check_mark: |\n| `*`         | `allOf`                |                    |\n| `*`         | `anyOf`                |                    |\n| `*`         | `oneOf`                |                    |\n| `*`         | `not`                  |                    |\n\n## Known Limitations\n\nAvoid circular refs in your schema. Schema below can cause infinite loop and `Out of Memory` PHP error:\n```yml\n# ModelA has reference to ModelB while ModelB has reference to ModelA.\n# Mock server will produce huge nested JSON example and ended with `Out of Memory` error.\ndefinitions:\n  ModelA:\n    type: object\n    properties:\n      model_b:\n        $ref: '#/definitions/ModelB'\n  ModelB:\n    type: array\n    items:\n      $ref: '#/definitions/ModelA'\n```\n\nDon't ref scalar types, because generator will not produce models which mock server can find. So schema below will cause error:\n```yml\n# generated build contains only `OuterComposite` model class which referenced to not existed `OuterNumber`, `OuterString`, `OuterBoolean` classes\n# mock server cannot mock `OuterComposite` model and throws exception\ndefinitions:\n  OuterComposite:\n    type: object\n    properties:\n      my_number:\n        $ref: '#/definitions/OuterNumber'\n      my_string:\n        $ref: '#/definitions/OuterString'\n      my_boolean:\n        $ref: '#/definitions/OuterBoolean'\n  OuterNumber:\n    type: number\n  OuterString:\n    type: string\n  OuterBoolean:\n    type: boolean\n```\n\n## Links to mentioned technologies\n\n* [OpenAPI Specification 3.0.3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md)\n* [OpenAPI Generator](https://openapi-generator.tech)\n* [Composer](https://getcomposer.org/download/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybelenko%2Fopenapi-data-mocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fybelenko%2Fopenapi-data-mocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybelenko%2Fopenapi-data-mocker/lists"}