1.0.3 • Published 4 years ago

smartify-schema v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

smartify-schema

JsonSchema for Fastify

Useage

var Schema = require("smartify-schema");

var schema = new Schema("common.js", "base schema")
.body("username").reg(/^\d+$/ig).error("abc")
.query("email").email().error("message")
.item("body.id").string().error("abc")
.headers("string").string().error("abc")
.item("boolean").boolean().error("abc")
.item("headers.enum").enum(1, 2, 3, 4, 5).error("abc")
.requiredBody("body", "bbc")
.requiredHeaders("body", "bbc")
.value()


console.log(schema)
{
  '$id': 'common.js',
  '$schema': 'http://json-schema.org/draft-007/schema',
  title: 'base schema',
  body: {
    username: { type: 'regexp', pattern: '^\\d+$', errorMessage: 'abc' },
    id: { type: 'string', errorMessage: 'abc' },
    required: [ 'body', 'bbc' ]
  },
  query: {
    email: {
      type: 'regexp',
      pattern: '^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$',
      errorMessage: 'message'
    }
  },
  headers: {
    string: { type: 'string', errorMessage: 'abc' },
    boolean: { type: 'boolean', errorMessage: 'abc' },
    enum: { type: 'string', enum: [], errorMessage: 'abc' },
    required: [ 'body', 'bbc' ]
  }
}
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago