mock-json-schema
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

mock-json-schema

CI Dependencies npm version npm downloads Total alerts Language grade: JavaScript License Sponsored Buy me a coffee

Simple utility to mock example objects based on JSON schema definitions

Features

  • [x] Minimal & deterministic. Predictable single example with no randomisation involved
  • [x] Thoroughly tested feature set
  • [x] Supports example, default
  • [x] Supports anyOf, allOf, oneOf
  • [x] Built-in examples for following string formats:
    • email
    • hostname
    • ipv4
    • ipv6
    • uri
    • uri-reference
    • uri-template
    • json-pointer
    • date-time
    • uuid
  • [x] TypeScript types included
  • [ ] Supports $ref pointers

Usage

const { mock } = require('mock-json-schema');
const assert = require('assert');

const schema = {
  type: 'array',
  items: {
    type: 'object',
    properties: {
      id: {
        type: 'integer',
        minimum: 1,
      },
      name: {
        type: 'string',
        example: 'John Doe',
      },
      email: {
        type: 'string',
        format: 'email',
      },
    },
  },
};

assert.deepEqual(mock(schema), [{ id: 1, name: 'John Doe', email: 'user@example.com' }]);

View more examples

Contributing

mock-json-schema is Free and Open Source Software. Issues and pull requests are more than welcome!

The Chilicorn

Package Sidebar

Install

npm i mock-json-schema

Weekly Downloads

28,043

Version

1.1.1

License

MIT

Unpacked Size

12.3 kB

Total Files

7

Last publish

Collaborators

  • anttiviljami