Skip to content

Commit f9fd517

Browse files
committed
Improve type checking
1 parent e798186 commit f9fd517

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/metamodel.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ function isValidObject(object, schema, strict, cleanRef) {
17371737
}
17381738

17391739
if (hasType(cleanRef, 'undefined')) {
1740-
strict = false;
1740+
cleanRef = false;
17411741
}
17421742

17431743
/*
@@ -1753,7 +1753,7 @@ function isValidObject(object, schema, strict, cleanRef) {
17531753
if (realType) {
17541754
switch (true) {
17551755
case !hasType(realType.schema, 'undefined'):
1756-
isValid = isValidObject(field, realType.schema);
1756+
isValid = isValidObject(field, realType.schema, strict, cleanRef);
17571757
break;
17581758
case !hasType(realType.value, 'undefined'):
17591759
isValid = isValidEnum(field, realType);
@@ -1826,7 +1826,7 @@ function isValidObject(object, schema, strict, cleanRef) {
18261826
break;
18271827
case 'string':
18281828
if (isCustomType(realType)) {
1829-
isValid = isValidObject(field, typeSchema);
1829+
isValid = isValidObject(field, typeSchema, strict, cleanRef);
18301830
} else {
18311831
if (typeSchema === 'array') {
18321832
if (getRealType(field) !== 'array') {
@@ -1907,6 +1907,11 @@ function isValidObject(object, schema, strict, cleanRef) {
19071907
return isValid;
19081908
}
19091909

1910+
// check if object
1911+
if (!hasType(object, 'object')) {
1912+
result = false;
1913+
$log.invalidType(object, 'object');
1914+
}
19101915

19111916
// type
19121917
for (fieldName in object) {
@@ -1952,7 +1957,7 @@ function isValidObject(object, schema, strict, cleanRef) {
19521957
for (fieldName in schema) {
19531958
field = schema[fieldName];
19541959
mandatory = field.mandatory;
1955-
if (hasType(object[fieldName], 'undefined')) {
1960+
if (object && hasType(object[fieldName], 'undefined')) {
19561961
if (mandatory === true) {
19571962
$log.missingProperty(fieldName);
19581963
result = false;

0 commit comments

Comments
 (0)