From 56bd40927932b668b052b3de612b1205549062c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Gy=C3=B6rffi?= Date: Sun, 5 Jul 2020 16:37:30 +0200 Subject: [PATCH] Skip validation of elements of array against additionalItems schema if "items" definition is missing --- .../everit/json/schema/ArraySchemaValidatingVisitor.java | 2 +- .../test/java/org/everit/json/schema/ArraySchemaTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/everit/json/schema/ArraySchemaValidatingVisitor.java b/core/src/main/java/org/everit/json/schema/ArraySchemaValidatingVisitor.java index bf92e06cc..82848dc24 100644 --- a/core/src/main/java/org/everit/json/schema/ArraySchemaValidatingVisitor.java +++ b/core/src/main/java/org/everit/json/schema/ArraySchemaValidatingVisitor.java @@ -93,7 +93,7 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner) { } @Override void visitSchemaOfAdditionalItems(Schema schemaOfAdditionalItems) { - if (schemaOfAdditionalItems == null) { + if (schemaOfAdditionalItems == null || arraySchema.getItemSchemas() == null) { return; } int validationFrom = Math.min(subjectLength, arraySchema.getItemSchemas().size()); diff --git a/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java b/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java index bbfea91df..47df2bede 100644 --- a/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java @@ -41,6 +41,13 @@ public void additionalItemsSchema() { .build().validate(ARRAYS.get("additionalItemsSchema")); } + @Test + public void ignoreAdditionalItemsIfNoItemsSchema() { + ArraySchema.builder() + .schemaOfAdditionalItems(FalseSchema.INSTANCE) + .build().validate(ARRAYS.get("noItemSchema")); + } + @Test public void additionalItemsSchemaFailure() { NullSchema nullSchema = buildWithLocation(NullSchema.builder());