Closed diversario closed 13 years ago
This correct, because the default fallbacks are tolerant, and additional properties are removed in this mode. Take a look at the fallbacks property in README.
But I did specify fallbacks: Schema.STRICT_FALLBACKS.
I tested README example with integer and string and in that schema strick fallbacks affect validation. How come I can't do the same with my schema?
You need to set fallbacks
in every schema that should be handled strictly.
For v0.2 I approach this design: https://github.com/akidee/schema.js/issues/11
Ughhh... I don't know what I'm doing wrong here, maybe you could take a look at this? var schemaAdd = Schema.create({ fallbacks: Schema.STRICT_FALLBACKS, description:"Schema", type:"object", additionalProperties: false, properties:{ data: {type: "object", required: true, additionalProperties: false, fallbacks: Schema.STRICT_FALLBACKS, properties: { entry_title: {type: "string", required: true}, entry_body: {type: "string", required: true}, id: {type: "integer", required: true} } } } });
This still validated JSON object with additional properties.
I'm sorry - you are right: It seems that the inner schema still does not strictly validate in v0.1.0a Please use the restruct branch, which will be v0.2.0 soon. In this branch, it works. Some corrections:
var s = schema.create({
description:"API schema",
type:"object",
fallbacks: schema.Validation.STRICT_FALLBACKS,
properties:{
data: {type: "object",
additionalProperties: false,
fallbacks: schema.Validation.STRICT_FALLBACKS,
properties: { entry_title: {type: "string"},
entry_body: {type: "string"},
blog_id: {type: "integer"}
}
}
}
})
1) Use schema.Validation.STRICT_FALLBACKS
2) required
is not available in draft 2, instead there is only optional
, which defaults to true
Phew, thank you :) I'll just wait for 0.2.0 then, to be in the clear.
Schema:
This validates the following JSON:
Is this an issue or am I missing something?