jenerator/jenerator

This package is abandoned and no longer maintained. No replacement package was suggested.

Generates JSON values from JSON Schema definitions for use as seed data, sample API responses, etc.

dev-master 2017-08-01 22:54 UTC

This package is not auto-updated.

Last update: 2021-04-11 14:46:55 UTC


README

Build Status codecov

This package generates JSON objects from JSON Schema definitions and fills them with random fake data. This is useful for creating sample seed data that must be in a specific structure, e.g. useful for API responses.

The functionality is similar to the json-schema-faker NodeJs package.

Installation

The recommended way to install this code is via Composer

Usage

In Code

<?php
require 'vendor/autoload.php';

Command Line

For command line usage, move into the jenerator/ directory and call its command.

php jenerator example:show path/to/schema.json

Supported Formats

Standard Formats

The JSON Schema spec defines some formats that all compliant validators should respect. Jenerator will produce appropriately formatted mock data for each of these standard formats

Custom Formats

The following formats are custom and are not defined by the official JSON Schema spec. They exist solely to facilitate the generation of realistic mock data. Compliant validators should ignore these custom formats and any other custom keywords they may reference. Using a custom format is useful way to have this library generate example data of that format, but it is recommended that you include other other validation keywords that will ensure that any example data will properly validate. For example, you may use a schema such as this to indicate a year:

{
   "type": "string",
   "format": "year"
}

But you should include some other keywords that other validators will respect, e.g.

{
    "type": "string",
    "format": "year",
    "pattern": "\d{4}"
 }

Internet

  • macaddress
  • tld
  • slug
  • password
  • username

Phone

Images

  • image-url supports keywords for "width" and "height" to specify integer dimensions.

File

  • mime-type
  • file-extension // no dot
  • user-agent

People

  • person-title
  • person-name
  • person-firstname
  • person-lastname

I18N (internationalization)

Algorithms : hashes etc

  • md5
  • sha1
  • sha256
  • uuid

Text

  • paragraphs

Date/time

  • unix-timestamp
  • date
  • time
  • am-pm
  • day-of-week
  • monthname
  • year
  • timezone

Colors

  • color-hex
  • color-rgb
  • color-name

Barcodes

  • isbn-10
  • isbn-13
  • ean-8
  • ean-13

Address

  • address-city
  • address-streetaddress
  • address-streetname
  • address-postcode
  • address-country

Latitude/Longitude

  • latitude
  • longitude
  • coordinates

Payment

  • creditcard-number
  • creditcard-type
  • creditcard-exp-date

// TODO: // iban // return (new Payment(Factory::create(getLocale())))->iban($countryCode); // });

  • swiftbic

Known Limitations

The jenerator does not support the "not" keyword. The value generator will generate a value, but it does not attempt to validate the result against any schema defined in the the not keyword; it does not attempt to re-generate a value if the generated value validates against the not schema.

Unreliable support for the "oneOf" keyword. The value generator will pick one of the listed schemas, but it does not validate the generated value against the other schemas and re-generate

No support for dependencies keyword

**arrayUnique may remove items from an array that may cause the array size to fall below the minItems requirement.