dsl-schema
So I herd U liek
JSON Schema
!
dsl-schema
provides simple, yet powerful API for building up your JSON Schema
s based on examples you provide.
const mySchema = // trueajv // falseajv
Getting started
npm install dsl-schema # OR yarn add dsl-schema
const schema =
Docs
like
like:Schema
- For object like
example
it builds up aRecord
of its properties - For array like
example
it builds up aTuple
of its elements - For primitive
example
it tries to guess the best schema for it:
like.Str
Str:Schema
Min and max length can be specified using opts
Str('10 > len')
Str('3 < length')
Str('3 < len <=10')
like.Float
Float:Schema
Min, max, and multipleOf can be specified using opts
Float('1.3 < x')
Float('1.3 < x <= 6')
Float('n*0.1')
Float('1.3 < x <= 6, n*2.6')
like.Int
Int:Schema
See Float
like.req
req:TaggedSchema
Tags schema as required
like.opt
req:TaggedSchema
Tags schema as optional
like.Tuple
Tuple:Schema
like.Record
Record:Schema
like.Dict
Dict:SchemaDict:Schema
Size of the dictionary can be specified using opts
Dict('size <= 10')
Dict('length > 10')
Dict('30 > len > 10')
like.List
List:SchemaList:Schema
See Dict
. Can also specify uniqueness
List('unique')
List('uniq, len < 30')
like.Enum
Enum:Schema
Elements of the items
must be unique
like.AllOf
AllOf:Schema
like.AnyOf
AnyOf:Schema
like.OneOf
OneOf:Schema
like.Not
Not:Schema
Constant schemas
ANY
BOOL
NULL
DATE
TIME
DATE_TIME
URI
URI_REFERENCE
URI_TEMPLATE
URL
EMAIL
HOSTNAME
IPV4
IPV6
REGEX
UUID