Skip to content

Commit 06ad306

Browse files
committed
renamed enum to enumeration
updated to be more strict
1 parent b951711 commit 06ad306

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
load_time: Duration,
9696
unload_time: Duration,
9797

98-
mobility: enum ("ambulatory", "wheelchair")
98+
mobility: enumeration ("ambulatory", "wheelchair")
9999
}
100100

101101
darp_schema = {

json-validate.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ json_validate = (function () {
3434
}
3535
};
3636

37-
function enum() {
37+
function enumeration() {
3838
var args = arguments;
3939

4040
return function(x)
@@ -108,24 +108,27 @@ json_validate = (function () {
108108
return true;
109109
}
110110
}
111-
112-
113-
114-
for (var item in schema)
111+
for (var item in object)
115112
{
116-
//if (item == "depot") debugger;
117-
if (schema.hasOwnProperty(item))
113+
if (object.hasOwnProperty(item))
118114
{
119-
var constraint = schema[item];
120-
var value = object[item];
121-
var r = validate(value, constraint);
115+
if (!schema.hasOwnProperty(item)) {
116+
var r = "not allowed here";
117+
}
118+
else {
119+
var constraint = schema[item];
120+
var value = object[item];
121+
var r = validate(value, constraint);
122+
}
123+
122124
if (r !== true) {
123125
error = true;
124126
errors[item] = r;
125127
}
126128

127129
}
128130
}
131+
129132

130133
if (error)
131134
return errors;
@@ -160,7 +163,7 @@ json_validate = (function () {
160163
object: object,
161164
optional: optional,
162165
of: of,
163-
enum: enum
166+
enumeration: enumeration
164167
}
165168

166169
return ret_fun;

0 commit comments

Comments
 (0)