Socket
Socket
Sign inDemoInstall

openapi-sampler

Package Overview
Dependencies
3
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    openapi-sampler

Tool for generation samples based on OpenAPI payload/response schema


Version published
Weekly downloads
661K
increased by3.5%
Maintainers
1
Install size
218 kB
Created
Weekly downloads
 

Readme

Source

openapi-sampler

Travis build status Coverage Status Dependency Status devDependency Status

Tool for generation samples based on OpenAPI payload/response schema

Features

  • Deterministic (given a particular input, will always produce the same output)
  • Supports compound keywords: allOf, oneOf, anyOf, if/then/else
  • Supports additionalProperties with x-additionalPropertiesName
  • Uses const, examples, enum and default where possible - in this order
  • Good array support: supports contains, minItems, maxItems, and tuples (items as an array)
  • Supports minLength, maxLength, min, max, exclusiveMinimum, exclusiveMaximum, (limited) pattern
  • Supports the following string formats:
    • email
    • idn-email
    • password
    • date-time
    • date
    • time
    • ipv4
    • ipv6
    • hostname
    • idn-hostname
    • uri
    • uri-reference
    • uri-template
    • iri
    • iri-reference
    • uuid
    • json-pointer
    • relative-json-pointer
    • regex
  • Infers schema type automatically following same rules as json-schema-faker
  • Support for $ref resolving
  • Has basic supports for JSON Schema draft 7 (thanks to @P0lip from @stoplightio for contributing)

Installation

Install using npm

npm install openapi-sampler

or using yarn

yarn add openapi-sampler

Then require it in your code:

var OpenAPISampler = require('openapi-sampler');

Usage

OpenAPISampler.sample(schema, [options], [spec])
  • schema (required) - object An OpenAPI Schema Object or a JSON Schema Draft 7 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 OpenAPISampler = require('.');
OpenAPISampler.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 24 Apr 2024

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