Skip to content

Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema

License

Notifications You must be signed in to change notification settings

Empia/openapi-sampler

 
 

Repository files navigation

openapi-sampler

Travis build status Code Climate 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 allOf
  • Supports additionalProperties
  • Uses default, example and enum 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

Installation

Node

Install using npm

npm install openapi-sampler --save

Then require it in your code:

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

Web Browsers

Install using bower:

bower install openapi-sampler

Then reference openapi-sampler.js in your HTML:

<script src="bower_components/openapi-sampler/openapi-sampler.js"></script>

Then use it via global exposed variable OpenAPISampler

Usage

OpenAPISampler.sample(schema, [options])

  • schema (required) - object A OpenAPI Schema Object
  • options (optional) - object Available options:
    • skipReadOnly - boolean Don't include readOnly object properties

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

About

Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.8%
  • HTML 0.2%