Socket
Socket
Sign inDemoInstall

@stoplight/json-schema-sampler

Package Overview
Dependencies
2
Maintainers
26
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @stoplight/json-schema-sampler

Tool for generation samples based on JSON Schema Draft 6


Version published
Maintainers
26
Created

Readme

Source

@stoplight/json-schema-sampler

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

Tool for generation samples based on JSON Schema Draft 6.

Features

  • deterministic (given a particular input, will always produce the same output)
  • Supports allOf
  • Supports additionalProperties
  • Uses default, const, enum and examples where possible
  • Full array support: supports minItems, and tuples (items as an array)
  • Supports minLength, maxLength, min, max, exclusiveMinimum, exclusiveMaximum
  • Supports the next string formats:
    • email
    • password
    • date-time
    • date
    • ipv4
    • ipv6
    • hostname
    • uri
    • uuid
  • Infers schema type automatically following same rules as json-schema-faker
  • Support for $ref resolving

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])
  • schema (required) - object A JSON Schema Draft 6 document.
  • options (optional) - object Available options:
    • skipNonRequired - boolean Don't include non-required object properties not specified in required property of the schema object
    • skipReadOnly - boolean Don't include readOnly object properties
    • skipWriteOnly - boolean Don't include writeOnly object properties
    • quiet - boolean Don't log console warning messages
  • spec - whole specification where the schema is taken from. Required only when schema may contain $ref. spec must not contain any external references

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' }

Keywords

FAQs

Last updated on 15 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc