stoplightio / json-schema-sampler

Other
8 stars 2 forks source link

@stoplight/json-schema-sampler

It's a fork of openapi-sampler by Redocly, with focus on supporting JSON Schema Draft 7.

Tool for generation samples based on JSON Schema Draft 7.

Features

Installation

Install using npm

npm install @stoplight/json-schema-sampler --save

or using yarn

yarn add @stoplight/json-schema-sampler

Then require it in your code:

const JSONSchemaSampler = require('@stoplight/json-schema-sampler');

Usage

JSONSchemaSampler.sample(schema, [options], [spec])

Example

const JSONSchemaSampler = require('@stoplight/json-schema-sampler');
JSONSchemaSampler.sample({
  type: 'object',
  properties: {
    a: {type: 'integer', minimum: 10},
    b: {type: 'string', format: 'password', minLength: 10},
    c: {type: 'boolean', readOnly: true}
  }
}, {skipReadOnly: true});
// { a: 10, b: 'pa$$word_q' }