serviceberry-json-schema

1.0.1 • Public • Published

serviceberry-json-schema

CircleCI Test Coverage Maintainability npm version

JSON Schema validator plugin for Serviceberry. For more information visit json-schema.org.

Install

npm install serviceberry-json-schema

Usage

This plugin exports a function that creates handlers. To use this plugin, call this function with a schema object and an optional options object. The second argument can also be a validator instance. Validators are objects with a compileAsync method that returns a validate function (such as a Ajv instance) If an options object is passed, a new Ajv instance is created.

const jsonSchema = require("serviceberry-json-schema");
 
trunk.use(jsonSchema({
    type: "object",
    properties: {
        firstName: {
            type: "string"
        },
        lastName: {
            type: "string"
        }
    },
    required: [
        "firstName",
        "lastName"
    ]
}));

async jsonSchema(schema[, param][, options])

async jsonSchema(schema[, param][, validator])

  • schema object

    JSON Schema

  • param string

    See above

  • validator object

    Ajv instance or any object that has a compileAsync method that takes the schema and returns a validate function.

Package Sidebar

Install

npm i serviceberry-json-schema

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

8.23 kB

Total Files

4

Last publish

Collaborators

  • bob-gray