GithubHelp home page GithubHelp logo

doc22940 / openapi-sampler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redocly/openapi-sampler

0.0 1.0 0.0 1.22 MB

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

License: MIT License

JavaScript 99.88% HTML 0.12%

openapi-sampler's Introduction

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 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
  • Infers schema type automatically following same rules as json-schema-faker
  • Support for $ref resolving

Installation

Install using npm

npm install openapi-sampler --save

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 A OpenAPI Schema Object
  • 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' }

openapi-sampler's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.