json-schema-mock
v0.0.8
Published
data mocker for json-schema.
Downloads
50
Maintainers
Readme
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
}