Mobitel Ltd. JSON-Schema template
A small helper for generating a JSON schema elements.
Attention
This module writing and testing on NodeJs v.8+ and NPM v.5+. Using the module in previous versions of NodeJs does not guarantee its correct operation.
Navigation
- Installation
- Example
- API
- Testing
- License
Installation
npm i --save mobitel-json-schema-template
Example
Writing JSON-schema
const jst = ; moduleexports = id: 'exampleSchema' type: 'object' additionalProperties: false required: 'propArray' 'propInteger' 'propNumber' 'propString' 'propEnum' 'propNull' 'propBoolean' 'propStringFormat' 'propAnyOf' 'propAllOf' 'propOneOf' 'propNot' 'propRef' properties: propArray: jst propInteger: jst propNumber: jst propString: jst propEnum: jst propNull: jst propBoolean: jst propStringFormat: jst propAnyOf: jst propAllOf: jst propOneOf: jst propNot: jst propRef: jst definitions: refExample: type: 'object' required: 'asString' 'asNumber' 'asNull' properties: asString: jst asNumber: jst asNull: jst ;
Result
API
Initializing
const jst = ;
Returns object for generating a JSON schema elements.
up to navigation
.allOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.anyOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.boolean([arg])
Arguments - Boolean
or 'all'
(default)
Example Boolean
jst;
Result Boolean
Example 'all'
jst;
Result 'all'
.enum(arg[, arg2[, arg3]...])
Arguments - Array|*
Can accept mix of Array
and *
Example
jst;
Result
.not(arg)
Arguments - Object
Example
jst;
Result
.null()
Arguments - no
Example
jst;
Result
.oneOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.ref(arg)
Arguments - String
Example
jst;
Result
.stringFormat(arg)
Arguments - String
Argument must be values like:
- date-time
- hostname
- ipv4
- ipv6
- uri
Example
jst;
Result
.array()
Arguments - no
Example
jst;
Result
.array().additional(arg)
Arguments - Boolean
Example
jst;
Result
.array().items(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.array().max(arg)
Arguments - positive Number
Example
jst;
Result
.array().min(arg)
Arguments - positive Number
Example
jst;
Result
.array().unique()
Arguments - no
Example
jst;
Result
.array().done()
Arguments - no Finalize creation JSON schema template by type and return complete object.
Example
jst;
Result
.integer()
Arguments - no
Example
jst;
Result
.integer().allOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.integer().anyOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.integer().eMax()
Arguments - no
Example
jst;
Result
.integer().eMin()
Arguments - no
Example
jst;
Result
.integer().enum(arg[, arg2[, arg3]...])
Arguments - Array|*
Can accept mix of Array
and *
Example
jst;
Result
.integer().max(arg)
Arguments - Number
as integer
Example
jst;
Result
.integer().min(arg)
Arguments - Number
as integer
Example
jst;
Result
.integer().multipleOf(arg)
Arguments - positive Number
as integer
Example
jst;
Result
.integer().not(arg)
Arguments - Object
Example
jst;
Result
.integer().oneOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.integer().done()
Arguments - no Finalize creation JSON schema template by type and return complete object.
Example
jst;
Result
.number()
Arguments - no
Example
jst;
Result
.number().allOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.number().anyOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.number().eMax()
Arguments - no
Example
jst;
Result
.number().eMin()
Arguments - no
Example
jst;
Result
.number().enum(arg[, arg2[, arg3]...])
Arguments - Array|*
Can accept mix of Array
and *
Example
jst;
Result
.number().max(arg)
Arguments - Number
Example
jst;
Result
.number().min(arg)
Arguments - Number
Example
jst;
Result
.number().multipleOf(arg)
Arguments - positive Number
as integer
Example
jst;
Result
.number().not(arg)
Arguments - Object
Example
jst;
Result
.number().oneOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.number().done()
Arguments - no Finalize creation JSON schema template by type and return complete object.
Example
jst;
Result
.string()
Arguments - no
Example
jst;
Result
.string().allOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.string().anyOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.string().enum(arg[, arg2[, arg3]...])
Arguments - Array|*
Can accept mix of Array
and *
Example
jst;
Result
.string().max(arg)
Arguments - positive Number
as integer
Example
jst;
Result
.string().min(arg)
Arguments - positive Number
as integer
Example
jst;
Result
.string().not(arg)
Arguments - Object
Example
jst;
Result
.string().oneOf(arg[, arg2[, arg3]...])
Arguments - Object[]|Object
Can accept mix of Object[]
and Object
Example
jst;
Result
.string().pattern(arg)
Arguments - RegExp|String
Example
jst;
Result
.string().done()
Arguments - no Finalize creation JSON schema template by type and return complete object.
Example
jst;
Result
Testing
npm run test
License
MIT License.
Copyright (c) 2017 Mobitel Ltd
up to navigation