schema2object
Generate random objects based on JSON Schema
Last updated 6 years ago by bebraw .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install schema2object 
SYNC missed versions from official npm registry.

build status

schema2object - Generate random objects based on JSON Schema

Usage:

// it is possible to replace generators with something else
// just implement {<json schema property> -> fn} where fn should return
// a generated value
var generators = require('annogenerate');

var schema2object = require('schema2object');
var definitions = ...; // Object of JSON schemas (name -> schema)
var definition = ...; // JSON Schema


var properties = definition.properties;

// if you want, you can generate data only for required fields
if(definition.required) {
    properties = schema2object.getRequiredProperties(definition);
}

var o = schema2object.properties2object({
    generators: generators,
    // fieldGenerators - optional generators that match per field name
    properties: properties,
    definitions: definitions // optional definitions for checking against $ref
});

// you should have an object with random data now
console.log(o);

See /demo for a more comprehensive example.

License

schema2object is available under MIT. See LICENSE for more details.

Current Tags

  • 0.4.0                                ...           latest (6 years ago)

8 Versions

  • 0.4.0                                ...           6 years ago
  • 0.3.4                                ...           6 years ago
  • 0.3.3                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2017 © taobao.org |