summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/node_modules/okschema/index.js12
-rw-r--r--examples/db.json4
2 files changed, 13 insertions, 3 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
index 51783a1..0829807 100644
--- a/app/node_modules/okschema/index.js
+++ b/app/node_modules/okschema/index.js
@@ -19,7 +19,15 @@ var types = {
'text': {
parent: {type: 'string'},
// Let parent handle validation
- assertValid: function(s) {}
+ assertValid: function(spec, value) {}
+ },
+ 'enum': {
+ parent: {type: 'string'},
+ assertValid: function(spec, value) {
+ if (~spec.options.indexOf(value)) {
+ throw []
+ }
+ }
}
}
@@ -59,7 +67,7 @@ OKSchema.prototype.assertValid = function(data) {
Object.keys(data).forEach(function(prop) {
var type = spec[prop].type;
if (types[type]) {
- types[type].assertValid(data[prop]);
+ types[type].assertValid(spec[prop], data[prop]);
}
});
var result = mschema.validate(data, this.toMschema());
diff --git a/examples/db.json b/examples/db.json
index e0ea06b..b2cdf4a 100644
--- a/examples/db.json
+++ b/examples/db.json
@@ -4,7 +4,9 @@
{
"type": "pretzel",
"description": "really a very tasty bread! yup yes",
- "id": "pretzel"
+ "color": "blue",
+ "id": "pretzel",
+ "title": ""
},
{
"type": "bagel",