Merge pull request #117 from stephensearles/master
fixed false validation error. positional array schemas are supposed to pass if the instance has too few items
diff --git a/errors.go b/errors.go
index 9ef4d4c..5146cbb 100644
--- a/errors.go
+++ b/errors.go
@@ -56,11 +56,6 @@
ResultErrorFields
}
- // ArrayNotEnoughItemsError. ErrorDetails: -
- ArrayNotEnoughItemsError struct {
- ResultErrorFields
- }
-
// ArrayMinItemsError. ErrorDetails: min
ArrayMinItemsError struct {
ResultErrorFields
@@ -177,9 +172,6 @@
case *ArrayNoAdditionalItemsError:
t = "array_no_additional_items"
d = locale.ArrayNoAdditionalItems()
- case *ArrayNotEnoughItemsError:
- t = "array_not_enough_items"
- d = locale.ArrayNotEnoughItems()
case *ArrayMinItemsError:
t = "array_min_items"
d = locale.ArrayMinItems()
diff --git a/json_schema_test_suite/items/data_20.json b/json_schema_test_suite/items/data_20.json
deleted file mode 100644
index 0ede6e1..0000000
--- a/json_schema_test_suite/items/data_20.json
+++ /dev/null
@@ -1 +0,0 @@
-["foo",1]
diff --git a/json_schema_test_suite/items/schema_2.json b/json_schema_test_suite/items/schema_2.json
deleted file mode 100644
index 5345d5f..0000000
--- a/json_schema_test_suite/items/schema_2.json
+++ /dev/null
@@ -1 +0,0 @@
-{"items":[{"type":"integer"},{"type":"string"},{"type":"string"}], "additionalItems": false}
diff --git a/schema_test.go b/schema_test.go
index c2c025a..5306ea1 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -248,7 +248,6 @@
{"phase": "a schema given for items", "test": "ignores non-arrays", "schema": "items/schema_0.json", "data": "items/data_02.json", "valid": "true"},
{"phase": "an array of schemas for items", "test": "correct types", "schema": "items/schema_1.json", "data": "items/data_10.json", "valid": "true"},
{"phase": "an array of schemas for items", "test": "wrong types", "schema": "items/schema_1.json", "data": "items/data_11.json", "valid": "false", "errors": "invalid_type, invalid_type"},
- {"phase": "an array of schemas for items", "test": "too many with wrong types", "schema": "items/schema_2.json", "data": "items/data_20.json", "valid": "false", "errors": "array_not_enough_items, invalid_type, invalid_type"},
{"phase": "valid definition", "test": "valid definition schema", "schema": "definitions/schema_0.json", "data": "definitions/data_00.json", "valid": "true"},
{"phase": "invalid definition", "test": "invalid definition schema", "schema": "definitions/schema_1.json", "data": "definitions/data_10.json", "valid": "false", "errors": "number_any_of, enum"},
{"phase": "additionalItems as schema", "test": "additional items match schema", "schema": "additionalItems/schema_0.json", "data": "additionalItems/data_00.json", "valid": "true"},
diff --git a/validation.go b/validation.go
index 920c17b..5b2230d 100644
--- a/validation.go
+++ b/validation.go
@@ -426,22 +426,14 @@
nbItems := len(currentSubSchema.itemsChildren)
- if nbItems > nbValues {
- // we have more positional schemas than we do items
- result.addError(new(ArrayNotEnoughItemsError), context, value, ErrorDetails{})
+ // while we have both schemas and values, check them against each other
+ for i := 0; i != nbItems && i != nbValues; i++ {
+ subContext := newJsonContext(strconv.Itoa(i), context)
+ validationResult := currentSubSchema.itemsChildren[i].subValidateWithContext(value[i], subContext)
+ result.mergeErrors(validationResult)
}
- if nbItems >= nbValues {
- // we have enough schemas to cover all our values, but use >=
- // so if we have too many schemas, we are covered by the above error
- // but we continue reporting if any of the items we already have don't
- // match their corresponding schema.
- for i := 0; i != nbItems && i != nbValues; i++ {
- subContext := newJsonContext(strconv.Itoa(i), context)
- validationResult := currentSubSchema.itemsChildren[i].subValidateWithContext(value[i], subContext)
- result.mergeErrors(validationResult)
- }
- } else if nbItems < nbValues {
+ if nbItems < nbValues {
// we have less schemas than elements in the instance array,
// but that might be ok if "additionalItems" is specified.