Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-mock-parser

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-mock-parser

use chance.js to parse definition schema to mock data

  • 1.1.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63
decreased by-30.77%
Maintainers
1
Weekly downloads
 
Created
Source

swagger-mock-parser

A parser for swagger object properties ,mock data returned by chancejs

##changeLog version 1.1.8 change: add useExample option,set this true parser will return defined example first version 1.1.7 break change: return string instead of throw error,objectParser canParse add "node.type == object" judge condition

usage

An example for mocking swagger definition schema

// basic usage
var Parser = require('swagger-mock-parser')
var parser = new Parser();
var schema = definition.schema;
return parser.parse(schema);

// useExample option
var Parser = require('swagger-mock-parser')
// set useExample true will return every property's example which has already defined
var parser = new Parser({useExample: true});
var schema = {type: 'string', example: 'will return example first'}
return parser.parse(schema);

Specifying custom Chance options

Swagger specifies only a few primitive types; for scenarios where specific chance methods are needed, use the x-chance-type field.

...
definitions:
  NewPet:
    properties:
      name:
        type: string
        x-chance-type: name
      tag:
        type: string
        x-chance-type: guid

Most of the chance methods allow some fine-tuning of the returned data. For example, the integer method allows specification of minimum and maximum output values. These options can be configured in the Swagger YAML file with the x-chance-options block:

...
definitions:
  Pet:
    allOf:
      - $ref: '#/definitions/NewPet'
      - required:
        - id
        properties:
          id:
            type: integer
            format: int64
            x-type-options:
              min: 1
              max: 1000

A note on types:

All of the primitive types defined in the Swagger specification are supported except for file and password. Currently, the format property is ignored; use x-chance-type instead. The server will error on any request with a type other than one of the primitive types if there is no valid x-chance-type also defined.

Returning Fixed Values

Although not a chance method, support has been added for returning fixed values using x-chance-type: fixed. Any value given for the custom tag x-type-value will be returned; below is an example where an object is returned:

    status:
      type: object
      x-chance-type: fixed
      x-type-value:
        type: 'adopted'

Keywords

FAQs

Package last updated on 16 Jun 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc