davidgwking / adhere Goto Github PK
View Code? Open in Web Editor NEWa schema-based data validator
License: MIT License
a schema-based data validator
License: MIT License
Helps describe the library's behavior for users. That's all.
Implement definitions
and $ref
utility keywords for sub-schema inlining and recursion.
// should validate [1, 2, [[[[[5], 4]]]], [2]]
{
// I am a nested array with terminal case positive integer
type: 'array',
items: { '$ref': '#recursiveArrayOfPositiveIntegers' },
definitions: {
recursiveArrayOfPositiveIntegers: {
type: ['array', 'number'],
items: { '$ref': '#recursiveArrayOfPositiveIntegers' },
minimum: 0,
exclusiveMinimum: true
}
}
}
// should validate [[[[[[5], 4]]]], [2]]
{
// I am an array of nested arrays with terminal case positive integer
type: 'array',
items: { '$ref': '#recursiveArrayOfPositiveIntegers' },
definitions: {
recursiveArrayOfPositiveIntegers: {
type: 'array',
items: { '$ref': '#recursiveArrayOfPositiveIntegers' },
// local definitions always take precedence
definitions: {
recursiveArrayOfPositiveIntegers: {
type: ['array', 'number'],
minimum: 0,
exclusiveMinimum: true,
items: { '$ref': '#recursiveArrayOfPositiveIntegers' },
}
}
}
}
}
{
type: 'object',
anyOf: [{'$ref': '#obj1'}, {'$ref': '#obj2'}],
definitions: {
obj1: {type: 'object', minProperties: 5, maxProperties: 9},
obj2: {type: 'object', minProperties: 10, maxProperties: 20}
}
}
Optimally, $ref
should be able to be used anywhere a sub-schema would typically be acceptable. Interpolated reference schemas should receive a definitions
object containing their own definition to enable schema recursion.
We will require an object recursion keyword in order to validate schemas since the universal structure is essential recursive.
// could allow mix ins
var s = {
type: 'object',
properties: {
a: {
type: 'object',
required: true,
// recurse on parent schema
recurse: true
}
},
patternProperties: {
'^b$': {
type: 'object',
// recurse on parent schema (s)
recurse: true
}
}
}
Provide a way to validate schemas.
It would be nice to have a standard format for errors while also providing error message overrides to be declared via schema.
initially support common formats:
Seek to streamline missing definitions
subschemas referred to by a $ref
. Currently, we depend on defaulting to an empty schema and the eventual discovery of a lack of type
in that empty schema.
Explore returning a schema error in this situation.
Wrap calls to conform
in a try-catch.
Explore returning a special message in this situation.
Browser compatibility perhaps using browserify
For each validation keyword, provide:
document errors returned for each keyword
mout has a pretty heavy footprint. Let's do what we can to remove the dependency as it was initially included to get up and running quicker.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.