json-schema-mock

0.0.8 • Public • Published

json-schema-mock

data mocker for json-schema.

Available keywords ( for now )

  • enum
  • properties
  • items
  • minItems
  • maxItems
  • minLength
  • maxLength
  • multipleOf
  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum
  • allOf,oneOf,anyOf
  • format 具体类型支持参考:json-schema-format

Usage

var DataMocker = require( 'json-schema-mock' );
var schema = {
     "type": "object",
     "description": "activity info",
     "properties": {
         "state": {
             "type": "string",
             "description": "current activity state",
             "enum": ["wait", "process", "over"]
         },
         "deadline": {
             "type": "number",
             "description": "deadline of the activity"
         },
         "remainDays": {
             "type": "integer",
             "description": "days left."
         }
     },
     "required": ["state", "deadline", "remainDays", "needDays", "seasonNum"]
}

console.log( DataMocker( schema ) );

Will output:

{
    state: 'wait',
    deadline: 5268.8,
    remainDays: 1460,
    needDays: 3315,
    seasonNum: 4
}

Dependents (2)

Package Sidebar

Install

npm i json-schema-mock

Weekly Downloads

1

Version

0.0.8

License

MIT

Last publish

Collaborators

  • abc-team