auto-json-schema
json-schema without pain
• Why • What • How • License •
Why
Because generating json-schema by hand is hard, complex and error prone.
What
The boiler plate stuff are inferred from the values of a model.
var autoS = var tedious = type: 'object' properties: 'qty': type: 'number' uid:type: 'string' $schema: 'http://json-schema.org/schema#'var easy = //same result as tedious
The model can contain nested json-schema and additional optional json-schema fragments can be provided to tweek the inferred values.
var autoS = var tedious = required: 'uid' type: 'object' properties: user: type: 'object' properties: age: minimum:18 type: 'number' uid: pattern: '[a-z]{4}' type: 'string' $schema: 'http://json-schema.org/schema#'var easier = //same result as tedious
How
autoSchema(model, schemaFragment, schemaFragment, ...)
model
: any valid json structure. The value can be sub-schema. Examples:3
: a standalone primitive{value: 3, password: anotherSchemaObject}
: a mix of values, tructures and schema
schemaFragment
: any valid parts of the json-schema standard. Last entries take precedence.{type: 'integer'}
: to overide the inferred type
License
Released under the MIT License