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

0.0.31 • Public • Published

A-Design Logo

🚀 apipost-mock-schema

Package Quality

Simple utility to mock example objects based on JSON schema definitions

Features

Minimal & deterministic. Predictable single example with no randomisation involved

TypeScript types included

Supports $ref pointers

Thoroughly tested feature set

Supports example, default

Supports anyOf, allOf, oneOf

Built-in examples for following string formats:

  • email
  • hostname
  • ipv4
  • ipv6
  • uri
  • uri-reference
  • uri-template
  • json-pointer
  • date-time
  • uuid

Install

$ npm install apipost-mock-schema

Usage

const schema = {
  type: 'array',
  items: {
    type: 'object',
    properties: {
      id: {
        type: 'integer',
        minimum: 1,
      },
      name: {
        type: 'string',
        example: 'John Doe',
      },
      email: {
        type: 'string',
        format: 'email',
      },
    },
  },
};
const MockSchema = require('apipost-mock-schema');
const myMockSchema = new MockSchema();

myMockSchema.mock(schema).then(res => {
    console.log(res)
    
    // will return
    /*
    [
        {
            "id": 7156472017141059,
            "name": "John Doe",
            "email": "y.hbm@tsqxod.dm"
        }
    ]
    */
}).catch(err => {
    console.log(err)
})

Package Sidebar

Install

npm i apipost-mock-schema

Weekly Downloads

11

Version

0.0.31

License

MIT

Unpacked Size

12 kB

Total Files

5

Last publish

Collaborators

  • chengyang12138
  • proud_lion
  • lee-meng
  • wjzhangq
  • apipost-lab001
  • xbw19975
  • trqdz