akidee / schema.js Goto Github PK
View Code? Open in Web Editor NEWSophisticated JSON schema based data validation and adaptation
License: MIT License
Sophisticated JSON schema based data validation and adaptation
License: MIT License
Hi!
MongoDB as primary keys uses _id
properties. When non-strict validating such instances _id
just gets deleted. How do I specify the default primary key name? Or should I specify it explicitly in every type: 'object'
schema?
TIA,
--Vladimir
Example problem: You need to specify different fallbacks
separately for every schema.
(To set default fallbacks (and other parameters) globally is not a good solution.)
Hi!
I'm sure you're aware of JS quirks in type detection, and e.g. typeof (new Number(4)) === 'object'
. This can completely break coercion logic. I'd suggest to use robust _.isXXX()
to determine the types of the instances, given you already required _
as dependency.
Best regards,
--Vladimir++
Schema:
Schema.create({
description:"API schema",
type:"object",
fallbacks: Schema.STRICT_FALLBACKS,
properties:{
data: {type: "object",
additionalProperties: false,
required: true,
properties: { entry_title: {type: "string", required: true},
entry_body: {type: "string", required: true},
blog_id: {type: "integer", required: true},
},
}
}
});
This validates the following JSON:
{data: {entry_title: "Title", entry_body: "Body", blog_id: "245232", zomg: "wtf"}}
Is this an issue or am I missing something?
Presently, I can't require('schema') and require('underscore') for npm installed versions of those libraries as schema.js references an older version of underscore (which it installs automatically, as a dependency) and there is some kind of naming conflict.
My node.js script throws the following error if I require both (but I can require either apart from the other):
exception: ReferenceError: _ is not defined
stack: ReferenceError: _ is not defined
Should we expect an update soon that will make it possible to use schema.js alongside the latest release of underscore?
Thanks for a great library, schema is beyond useful. :-)
Hi!
Suppose I have:
`
model.A = {properties:{
id: String, title: String
}}
model.B = {properties:{
id: String,
a: ???
}}
`
What should I substitute for definition of B.properties.a
to make it a validating reference to an instance of model.A? Which value should I then feed to B.properties.a
for schema to be valid?
TIA,
--Vladimir
When using minLength i allways get this error: TypeError: Cannot read property 'minLength' of undefined
var register_schema = schemaEnv.Schema.create({
type: 'object',
properties: {
email: {
type: 'string',
minLength: 6,
maxLength: 200,
optional: false
}
}
var v = register_schema.validate({email:'[email protected]'});
TypeError: Cannot read property 'minLength' of undefined
at /usr/local/lib/node_modules/schema/i18n/default.js:23:57
at new (/usr/local/lib/node_modules/schema/lib/validation.js:69:44)
at [object Object]. (/usr/local/lib/node_modules/schema/lib/validation.js:205:14)
at [object Object].callPlugin (/usr/local/lib/node_modules/schema/lib/validation.js:186:18)
at [object Object].minLength (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:453:12)
at [object Object].type (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:148:22)
at [object Object].start (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:37:20)
at [object Object].properties (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:276:18)
at [object Object].type (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:174:22)
at [object Object].start (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:37:20)
Code:
var env = require('schema')('envIdentifier', {});
var schema1 = env.Schema.create({
...
});
throws
ReferenceError: Schema is not defined
at that second line.
Started after latest update.
How can I assign a default to a $ref-erencing property:
lang: {$ref: 'Language.properties.id', default: 'ru'}
doesn't work. Assigning 'default' attribute to id
property of Language schema works, but by sense is not right, for I want to overwrite defaults in referencing properties.
Any clue?
TIA,
--Vladimir
Please, create the subj, or schema.js dependencies are not solved by module loaders (nodules, npm)
TIA,
--Vladimir
Hi!
{a: ''}
fails to validate tolerantly against a: {type: 'number', optional: true}
. I'd think a
should be just ignored, as it is optional, when a validation fails, no?
--dvv
Hi!
http://github.com/akidee/schema.js/blob/master/index.js#L237 constantly throws since __type member is undefined. Typo?
--Vladimir
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.