diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java
new file mode 100644
index 00000000..0c4ca96b
--- /dev/null
+++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java
@@ -0,0 +1,32 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2023 sebastian.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package io.github.sebastiantoepfer.jsonschema;
+
+/**
+ *
+ * see: https://json-schema.org/draft/2020-12/json-schema-core#name-root-schema-and-subschemas-
+ */
+public interface JsonSubSchema extends JsonSchema {
+ JsonSchema owner();
+}
diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordType.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordType.java
index edb6a275..ec84aba6 100644
--- a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordType.java
+++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.keyword;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import jakarta.json.JsonValue;
import java.util.Objects;
@@ -33,5 +34,5 @@ default boolean hasName(String name) {
String name();
- Keyword createKeyword(JsonValue value);
+ Keyword createKeyword(JsonSchema schema, JsonValue value);
}
diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordTypeTest.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordTypeTest.java
index 028e7290..af5e8364 100644
--- a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordTypeTest.java
+++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/keyword/KeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -45,7 +46,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
diff --git a/core/pom.xml b/core/pom.xml
index e5e55021..53dc2efd 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -167,6 +167,16 @@
**/tests/draft2019-09/multipleOf.json
**/tests/draft2020-12/multipleOf.json
**/tests/draft-next/multipleOf.json
+
+
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java
index ebe4f145..b6086174 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java
@@ -50,7 +50,7 @@ public Validator validator() {
return asJsonObject()
.entrySet()
.stream()
- .map(keywords::createKeywordFor)
+ .map(keyword -> keywords.createKeywordFor(this, keyword))
.filter(Constraint.class::isInstance)
.map(k -> (Constraint) k)
.collect(
@@ -60,7 +60,7 @@ public Validator validator() {
private Collection vocabulary() {
return new KeywordSearch(new VocabularyKeywordType())
- .searchForKeywordIn(asJsonObject())
+ .searchForKeywordIn(this)
.filter(VocabularyDefinitions.class::isInstance)
.map(VocabularyDefinitions.class::cast)
.stream()
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java
index 5c5c9325..542c4127 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java
@@ -23,9 +23,9 @@
*/
package io.github.sebastiantoepfer.jsonschema.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
-import jakarta.json.JsonObject;
import java.util.Objects;
import java.util.Optional;
@@ -37,7 +37,9 @@ public KeywordSearch(final KeywordType keywordType) {
this.keywordType = Objects.requireNonNull(keywordType);
}
- public Optional searchForKeywordIn(final JsonObject schema) {
- return Optional.ofNullable(schema.get(keywordType.name())).map(keywordType::createKeyword);
+ public Optional searchForKeywordIn(final JsonSchema schema) {
+ return Optional
+ .ofNullable(schema.asJsonObject().get(keywordType.name()))
+ .map(keywordValue -> keywordType.createKeyword(schema, keywordValue));
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/Keywords.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/Keywords.java
index 91f2c14d..793afba5 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/Keywords.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/Keywords.java
@@ -26,6 +26,7 @@
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.toMap;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.Vocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.basic.BasicVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.core.CoreLazyVocabulary;
@@ -80,13 +81,13 @@ public Keywords(final Collection vocabDefs) {
);
}
- public Keyword createKeywordFor(final Map.Entry property) {
+ public Keyword createKeywordFor(final JsonSchema schema, final Map.Entry property) {
return vocabularies
.stream()
.map(vocab -> vocab.findKeywordTypeByName(property.getKey()))
.flatMap(Optional::stream)
.findFirst()
- .map(keywordType -> keywordType.createKeyword(property.getValue()))
+ .map(keywordType -> keywordType.createKeyword(schema, property.getValue()))
.orElseThrow();
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabulary.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabulary.java
index 0616c530..ec37ea62 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabulary.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabulary.java
@@ -46,7 +46,8 @@ public BasicVocabulary() {
new ExclusiveMinimumKeywordType(),
new MaximumKeywordType(),
new ExclusiveMaximumKeywordType(),
- new MultipleOfKeywordType()
+ new MultipleOfKeywordType(),
+ new ItemsKeywordType()
);
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordType.java
index 34ccc188..ae18dca2 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.NUMBER.isInstance(value)) {
return new ExclusiveMaximumKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordType.java
index 5cea078d..938fa196 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.NUMBER.isInstance(value)) {
return new ExclusiveMinimumKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordType.java
new file mode 100644
index 00000000..16a2f1fa
--- /dev/null
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordType.java
@@ -0,0 +1,100 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2023 sebastian.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package io.github.sebastiantoepfer.jsonschema.core.vocab.basic;
+
+import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
+import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.JsonSchemas;
+import io.github.sebastiantoepfer.jsonschema.JsonSubSchema;
+import io.github.sebastiantoepfer.jsonschema.Validator;
+import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
+import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
+import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonValue;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+final class ItemsKeywordType implements KeywordType {
+
+ @Override
+ public String name() {
+ return "items";
+ }
+
+ @Override
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
+ return new ItemsKeyword(schema, JsonSchemas.load(value));
+ }
+
+ private class ItemsKeyword implements ConstraintAssertion, JsonSubSchema {
+
+ private final JsonSchema owner;
+ private final JsonSchema schema;
+
+ public ItemsKeyword(final JsonSchema owner, final JsonSchema schema) {
+ this.owner = Objects.requireNonNull(owner);
+ this.schema = Objects.requireNonNull(schema);
+ }
+
+ @Override
+ public JsonSchema owner() {
+ return owner;
+ }
+
+ @Override
+ public Validator validator() {
+ return schema.validator();
+ }
+
+ @Override
+ public ValueType getValueType() {
+ return schema.getValueType();
+ }
+
+ @Override
+ public boolean hasName(final String name) {
+ return Objects.equals(name(), name);
+ }
+
+ @Override
+ public Collection violationsBy(final JsonValue value) {
+ final Collection result;
+ if (!InstanceType.ARRAY.isInstance(value) || matchesSchema(value.asJsonArray())) {
+ result = Collections.emptyList();
+ } else {
+ result = List.of(new ConstraintViolation());
+ }
+ return result;
+ }
+
+ private boolean matchesSchema(final JsonArray items) {
+ final Validator itemValidator = validator();
+ return items.stream().map(itemValidator::validate).allMatch(Collection::isEmpty);
+ }
+ }
+}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordType.java
index 944fa465..b10564ab 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.INTEGER.isInstance(value)) {
return new MaxLengthKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordType.java
index e41d8463..b04dc35e 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.NUMBER.isInstance(value)) {
return new MaximumKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordType.java
index 0c81099b..010b9068 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.INTEGER.isInstance(value)) {
return new MinLengthKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordType.java
index d923a363..99ecbb78 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.NUMBER.isInstance(value)) {
return new MinimumKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordType.java
index 7fd33a92..aae9fdbf 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.NUMBER.isInstance(value)) {
return new MultipleOfKeyword((JsonNumber) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordType.java
index 85ffaf05..800c734a 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordType.java
@@ -25,6 +25,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -44,7 +45,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
if (InstanceType.STRING.isInstance(value)) {
return new PatternKeyword((JsonString) value);
} else {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordType.java
index c3ef73f4..6395b236 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordType.java
@@ -28,6 +28,7 @@
import io.github.sebastiantoepfer.jsonschema.ConstraintViolation;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.constraint.AnyConstraint;
import io.github.sebastiantoepfer.jsonschema.core.constraint.Constraint;
import io.github.sebastiantoepfer.jsonschema.core.vocab.ConstraintAssertion;
@@ -52,7 +53,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new TypeKeyword(value);
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/UnknowKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/UnknowKeywordType.java
index d3d86476..cad85212 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/UnknowKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/UnknowKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.basic;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.DefaultAnnotation;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -43,7 +44,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new DefaultAnnotation(name(), value);
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordType.java
index 985f2922..bcace34a 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.DefaultAnnotation;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -40,7 +41,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new DefaultAnnotation(name(), value);
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordType.java
index ed4e0d33..dfea7f9f 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.DefaultAnnotation;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -40,7 +41,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new DefaultAnnotation(name(), value);
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordType.java
index 390c58b4..49821a6d 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Applicator;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -41,7 +42,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new Applicator() {
@Override
public boolean applyTo(final JsonValue instance) {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordType.java
index 6bf3fa21..67b693b0 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.DefaultAnnotation;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -40,7 +41,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new DefaultAnnotation(name(), value);
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordType.java
index b59ba3a6..234d814b 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Applicator;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -41,7 +42,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new Applicator() {
@Override
public boolean applyTo(final JsonValue instance) {
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordType.java
index 926ec37c..a8192bec 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordType.java
@@ -23,6 +23,7 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.DefaultAnnotation;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
@@ -40,7 +41,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
return new DefaultAnnotation(name(), value);
}
}
diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordType.java
index 2ff582e8..92177c7f 100644
--- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordType.java
+++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordType.java
@@ -24,6 +24,7 @@
package io.github.sebastiantoepfer.jsonschema.core.vocab.core;
import io.github.sebastiantoepfer.jsonschema.InstanceType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition;
@@ -47,7 +48,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
final Keyword result;
if (InstanceType.OBJECT.isInstance(value)) {
result = new VocabularyKeyword(value);
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabularyTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabularyTest.java
index 75962d00..c5369f86 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabularyTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/BasicVocabularyTest.java
@@ -27,7 +27,7 @@
import static org.hamcrest.Matchers.is;
import com.github.npathai.hamcrestopt.OptionalMatchers;
-import io.github.sebastiantoepfer.jsonschema.core.vocab.basic.BasicVocabulary;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
import jakarta.json.JsonValue;
import java.net.URI;
@@ -56,7 +56,9 @@ void should_return_the_custom_annotation_for_unknow_keyword() {
assertThat(
new BasicVocabulary()
.findKeywordTypeByName("unknow")
- .map(keywordType -> keywordType.createKeyword(JsonValue.FALSE))
+ .map(keywordType ->
+ keywordType.createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE)
+ )
.map(keyword -> keyword.hasName("unknow")),
OptionalMatchers.isPresentAndIs(true)
);
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordTypeTest.java
index b0d96614..907374d7 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMaximumKeywordTypeTest.java
@@ -26,6 +26,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -36,7 +38,8 @@ class ExclusiveMaximumKeywordTypeTest {
@Test
void should_know_his_name() {
- final Keyword maximum = new ExclusiveMaximumKeywordType().createKeyword(Json.createValue(1));
+ final Keyword maximum = new ExclusiveMaximumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(maximum.hasName("exclusiveMaximum"), is(true));
assertThat(maximum.hasName("test"), is(false));
@@ -45,14 +48,18 @@ void should_know_his_name() {
@Test
void should_not_becreatable_with_non_number() {
final ExclusiveMaximumKeywordType keywordType = new ExclusiveMaximumKeywordType();
- Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.FALSE)
+ );
}
@Test
void should_be_valid_for_non_number_values() {
assertThat(
new ExclusiveMaximumKeywordType()
- .createKeyword(Json.createValue(1))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_OBJECT),
is(true)
@@ -63,7 +70,7 @@ void should_be_valid_for_non_number_values() {
void should_be_invalid_for_greater_numbers() {
assertThat(
new ExclusiveMaximumKeywordType()
- .createKeyword(Json.createValue(10))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
.asAssertion()
.isValidFor(Json.createValue(11)),
is(false)
@@ -74,7 +81,7 @@ void should_be_invalid_for_greater_numbers() {
void should_be_invalid_for_equals_numbers() {
assertThat(
new ExclusiveMaximumKeywordType()
- .createKeyword(Json.createValue(10))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
.asAssertion()
.isValidFor(Json.createValue(10)),
is(false)
@@ -85,7 +92,7 @@ void should_be_invalid_for_equals_numbers() {
void shhould_be_valid_for_smaller_numbers() {
assertThat(
new ExclusiveMaximumKeywordType()
- .createKeyword(Json.createValue(10))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
.asAssertion()
.isValidFor(Json.createValue(9)),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordTypeTest.java
index 004abf7b..ea1d0ebd 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ExclusiveMinimumKeywordTypeTest.java
@@ -26,6 +26,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -36,7 +38,8 @@ class ExclusiveMinimumKeywordTypeTest {
@Test
void should_know_his_name() {
- final Keyword minimum = new ExclusiveMinimumKeywordType().createKeyword(Json.createValue(1));
+ final Keyword minimum = new ExclusiveMinimumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(minimum.hasName("exclusiveMinimum"), is(true));
assertThat(minimum.hasName("test"), is(false));
@@ -45,14 +48,18 @@ void should_know_his_name() {
@Test
void should_not_becreatable_with_non_number() {
final ExclusiveMinimumKeywordType keywordType = new ExclusiveMinimumKeywordType();
- Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.FALSE)
+ );
}
@Test
void should_be_valid_for_non_number_values() {
assertThat(
new ExclusiveMinimumKeywordType()
- .createKeyword(Json.createValue(1))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_OBJECT),
is(true)
@@ -63,7 +70,7 @@ void should_be_valid_for_non_number_values() {
void should_be_invalid_for_smaller_numbers() {
assertThat(
new ExclusiveMinimumKeywordType()
- .createKeyword(Json.createValue(0))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
.asAssertion()
.isValidFor(Json.createValue(-1)),
is(false)
@@ -74,7 +81,7 @@ void should_be_invalid_for_smaller_numbers() {
void should_be_invalid_for_equals_numbers() {
assertThat(
new ExclusiveMinimumKeywordType()
- .createKeyword(Json.createValue(0))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
.asAssertion()
.isValidFor(Json.createValue(0)),
is(false)
@@ -85,7 +92,7 @@ void should_be_invalid_for_equals_numbers() {
void shhould_be_valid_for_greater_numbers() {
assertThat(
new ExclusiveMinimumKeywordType()
- .createKeyword(Json.createValue(0))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
.asAssertion()
.isValidFor(Json.createValue(1)),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordTypeTest.java
new file mode 100644
index 00000000..52e6eedf
--- /dev/null
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/ItemsKeywordTypeTest.java
@@ -0,0 +1,97 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2023 sebastian.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package io.github.sebastiantoepfer.jsonschema.core.vocab.basic;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.JsonSubSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
+import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
+import jakarta.json.Json;
+import jakarta.json.JsonValue;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+class ItemsKeywordTypeTest {
+
+ @Test
+ void should_know_his_name() {
+ final Keyword items = new ItemsKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT);
+
+ assertThat(items.hasName("items"), is(true));
+ assertThat(items.hasName("test"), is(false));
+ }
+
+ @Test
+ void should_be_invalid_if_items_does_not_match_schema() {
+ assertThat(
+ new ItemsKeywordType()
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ Json.createObjectBuilder().add("type", "number").build()
+ )
+ .asAssertion()
+ .isValidFor(Json.createArrayBuilder().add(1).add("invalid").add(2).build()),
+ is(false)
+ );
+ }
+
+ @Test
+ void should_be_valid_if_all_items_match_schema() {
+ assertThat(
+ new ItemsKeywordType()
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ Json.createObjectBuilder().add("type", "number").build()
+ )
+ .asAssertion()
+ .isValidFor(Json.createArrayBuilder().add(1).add(2).build()),
+ is(true)
+ );
+ }
+
+ @Test
+ void should_return_his_owning_schema() {
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ assertThat(
+ ((JsonSubSchema) new ItemsKeywordType().createKeyword(schema, JsonValue.TRUE)).owner(),
+ is(Matchers.sameInstance(schema))
+ );
+ }
+
+ @Test
+ void should_return_his_json_valuetype() {
+ assertThat(
+ ((JsonSubSchema) new ItemsKeywordType()
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ JsonValue.EMPTY_JSON_OBJECT
+ )).getValueType(),
+ is(JsonValue.ValueType.OBJECT)
+ );
+ }
+}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordTypeTest.java
index 12515cd1..37d9b75f 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaxLengthKeywordTypeTest.java
@@ -27,6 +27,8 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonNumber;
@@ -39,12 +41,14 @@ class MaxLengthKeywordTypeTest {
void should_not_be_createbale_with_non_integer() {
final JsonNumber value = Json.createValue(12.3);
final MinLengthKeywordType keywordType = new MinLengthKeywordType();
- assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(value));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, value));
}
@Test
void should_know_his_name() {
- final Keyword keyword = new MaxLengthKeywordType().createKeyword(Json.createValue(1));
+ final Keyword keyword = new MaxLengthKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(keyword.hasName("test"), is(false));
assertThat(keyword.hasName("maxLength"), is(true));
@@ -54,7 +58,7 @@ void should_know_his_name() {
void should_be_valid_for_non_string_values() {
assertThat(
new MaxLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_ARRAY),
is(true)
@@ -65,7 +69,7 @@ void should_be_valid_for_non_string_values() {
void should_be_invalid_for_longer_string() {
assertThat(
new MaxLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("1234")),
is(false)
@@ -76,7 +80,7 @@ void should_be_invalid_for_longer_string() {
void should_be_valid_for_string_with_length_is_equal() {
assertThat(
new MaxLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("12")),
is(true)
@@ -87,7 +91,7 @@ void should_be_valid_for_string_with_length_is_equal() {
void should_ne_valid_for_string_with_is_shorter() {
assertThat(
new MaxLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("1")),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordTypeTest.java
index 0e9f4b45..6748c608 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MaximumKeywordTypeTest.java
@@ -26,6 +26,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -36,7 +38,8 @@ class MaximumKeywordTypeTest {
@Test
void should_know_his_name() {
- final Keyword maximum = new MaximumKeywordType().createKeyword(Json.createValue(1));
+ final Keyword maximum = new MaximumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(maximum.hasName("maximum"), is(true));
assertThat(maximum.hasName("test"), is(false));
@@ -45,14 +48,18 @@ void should_know_his_name() {
@Test
void should_not_becreatable_with_non_number() {
final MaximumKeywordType keywordType = new MaximumKeywordType();
- Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.FALSE)
+ );
}
@Test
void should_be_valid_for_non_number_values() {
assertThat(
new MaximumKeywordType()
- .createKeyword(Json.createValue(1))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_OBJECT),
is(true)
@@ -62,7 +69,10 @@ void should_be_valid_for_non_number_values() {
@Test
void should_be_invalid_for_greater_numbers() {
assertThat(
- new MaximumKeywordType().createKeyword(Json.createValue(10)).asAssertion().isValidFor(Json.createValue(11)),
+ new MaximumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
+ .asAssertion()
+ .isValidFor(Json.createValue(11)),
is(false)
);
}
@@ -70,7 +80,10 @@ void should_be_invalid_for_greater_numbers() {
@Test
void should_be_valid_for_equals_numbers() {
assertThat(
- new MaximumKeywordType().createKeyword(Json.createValue(10)).asAssertion().isValidFor(Json.createValue(10)),
+ new MaximumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
+ .asAssertion()
+ .isValidFor(Json.createValue(10)),
is(true)
);
}
@@ -78,7 +91,10 @@ void should_be_valid_for_equals_numbers() {
@Test
void shhould_be_valid_for_smaller_numbers() {
assertThat(
- new MaximumKeywordType().createKeyword(Json.createValue(10)).asAssertion().isValidFor(Json.createValue(9)),
+ new MaximumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
+ .asAssertion()
+ .isValidFor(Json.createValue(9)),
is(true)
);
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordTypeTest.java
index 4ffa733f..807c1be3 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinLengthKeywordTypeTest.java
@@ -27,6 +27,8 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonNumber;
@@ -39,12 +41,14 @@ class MinLengthKeywordTypeTest {
void should_not_be_createbale_with_non_integer() {
final JsonNumber value = Json.createValue(12.3);
final MinLengthKeywordType keywordType = new MinLengthKeywordType();
- assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(value));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, value));
}
@Test
void should_know_his_name() {
- final Keyword keyword = new MinLengthKeywordType().createKeyword(Json.createValue(1));
+ final Keyword keyword = new MinLengthKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(keyword.hasName("test"), is(false));
assertThat(keyword.hasName("minLength"), is(true));
@@ -54,7 +58,7 @@ void should_know_his_name() {
void should_be_invalid_with_shorter_string() {
assertThat(
new MinLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("A")),
is(false)
@@ -65,7 +69,7 @@ void should_be_invalid_with_shorter_string() {
void should_be_valid_with_string_with_equal_length() {
assertThat(
new MinLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("AB")),
is(true)
@@ -76,7 +80,7 @@ void should_be_valid_with_string_with_equal_length() {
void should_be_valid_with_string_that_is_longer() {
assertThat(
new MinLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue("ABC")),
is(true)
@@ -87,7 +91,7 @@ void should_be_valid_with_string_that_is_longer() {
void should_be_valid_for_non_string_values() {
assertThat(
new MinLengthKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_ARRAY),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordTypeTest.java
index 59b976d7..23b85aa1 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MinimumKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -36,7 +37,8 @@ class MinimumKeywordTypeTest {
@Test
void should_know_his_name() {
- final Keyword minimum = new MinimumKeywordType().createKeyword(Json.createValue(1));
+ final Keyword minimum = new MinimumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1));
assertThat(minimum.hasName("minimum"), is(true));
assertThat(minimum.hasName("test"), is(false));
@@ -45,14 +47,18 @@ void should_know_his_name() {
@Test
void should_not_becreatable_with_non_number() {
final MinimumKeywordType keywordType = new MinimumKeywordType();
- Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final var schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.FALSE)
+ );
}
@Test
void should_be_valid_for_non_number_values() {
assertThat(
new MinimumKeywordType()
- .createKeyword(Json.createValue(1))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_OBJECT),
is(true)
@@ -62,7 +68,10 @@ void should_be_valid_for_non_number_values() {
@Test
void should_be_invalid_for_smaller_numbers() {
assertThat(
- new MinimumKeywordType().createKeyword(Json.createValue(0)).asAssertion().isValidFor(Json.createValue(-1)),
+ new MinimumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
+ .asAssertion()
+ .isValidFor(Json.createValue(-1)),
is(false)
);
}
@@ -70,7 +79,10 @@ void should_be_invalid_for_smaller_numbers() {
@Test
void should_be_valid_for_equals_numbers() {
assertThat(
- new MinimumKeywordType().createKeyword(Json.createValue(0)).asAssertion().isValidFor(Json.createValue(0)),
+ new MinimumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
+ .asAssertion()
+ .isValidFor(Json.createValue(0)),
is(true)
);
}
@@ -78,7 +90,10 @@ void should_be_valid_for_equals_numbers() {
@Test
void shhould_be_valid_for_greater_numbers() {
assertThat(
- new MinimumKeywordType().createKeyword(Json.createValue(0)).asAssertion().isValidFor(Json.createValue(1)),
+ new MinimumKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0))
+ .asAssertion()
+ .isValidFor(Json.createValue(1)),
is(true)
);
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordTypeTest.java
index 302c9b28..2f818951 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/MultipleOfKeywordTypeTest.java
@@ -27,6 +27,8 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -37,7 +39,8 @@ class MultipleOfKeywordTypeTest {
@Test
void should_know_his_name() {
- final Keyword multipleOf = new MultipleOfKeywordType().createKeyword(Json.createValue(10));
+ final Keyword multipleOf = new MultipleOfKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10));
assertThat(multipleOf.hasName("multipleOf"), is(true));
assertThat(multipleOf.hasName("test"), is(false));
@@ -46,14 +49,15 @@ void should_know_his_name() {
@Test
void should_not_be_creatable_with_non_integer_value() {
final MultipleOfKeywordType keywordType = new MultipleOfKeywordType();
- assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, JsonValue.FALSE));
}
@Test
void should_be_valid_for_non_number_values() {
assertThat(
new MultipleOfKeywordType()
- .createKeyword(Json.createValue(10))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10))
.asAssertion()
.isValidFor(JsonValue.EMPTY_JSON_OBJECT),
is(true)
@@ -64,7 +68,7 @@ void should_be_valid_for_non_number_values() {
void should_be_valid_for_a_multipleOf() {
assertThat(
new MultipleOfKeywordType()
- .createKeyword(Json.createValue(1.5))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1.5))
.asAssertion()
.isValidFor(Json.createValue(4.5)),
is(true)
@@ -75,7 +79,7 @@ void should_be_valid_for_a_multipleOf() {
void should_be_invalid_for_non_multipleOf() {
assertThat(
new MultipleOfKeywordType()
- .createKeyword(Json.createValue(2))
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2))
.asAssertion()
.isValidFor(Json.createValue(7)),
is(false)
@@ -86,7 +90,10 @@ void should_be_invalid_for_non_multipleOf() {
void should_be_valid_for_any_int_if_multipleOf_is_1en8() {
assertThat(
new MultipleOfKeywordType()
- .createKeyword(Json.createValue(new BigDecimal("1e-8")))
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ Json.createValue(new BigDecimal("1e-8"))
+ )
.asAssertion()
.isValidFor(Json.createValue(12391239123L)),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordTypeTest.java
index 539436d0..57ff8dc1 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/PatternKeywordTypeTest.java
@@ -27,6 +27,8 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -37,12 +39,17 @@ class PatternKeywordTypeTest {
@Test
void should_be_not_createbale_from_non_string() {
final PatternKeywordType keywordType = new PatternKeywordType();
- assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.EMPTY_JSON_OBJECT));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.EMPTY_JSON_OBJECT)
+ );
}
@Test
void should_be_know_his_name() {
- final Keyword pattern = new PatternKeywordType().createKeyword(Json.createValue("a"));
+ final Keyword pattern = new PatternKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("a"));
assertThat(pattern.hasName("pattern"), is(true));
assertThat(pattern.hasName("test"), is(false));
@@ -51,7 +58,10 @@ void should_be_know_his_name() {
@Test
void should_be_valid_for_non_string_value() {
assertThat(
- new PatternKeywordType().createKeyword(Json.createValue("a")).asAssertion().isValidFor(JsonValue.TRUE),
+ new PatternKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("a"))
+ .asAssertion()
+ .isValidFor(JsonValue.TRUE),
is(true)
);
}
@@ -60,7 +70,10 @@ void should_be_valid_for_non_string_value() {
void should_be_invalid_for_non_matching_value() {
assertThat(
new PatternKeywordType()
- .createKeyword(Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$"))
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$")
+ )
.asAssertion()
.isValidFor(Json.createValue("(888)555-1212 ext. 532")),
is(false)
@@ -71,7 +84,10 @@ void should_be_invalid_for_non_matching_value() {
void should_be_valid_matching_value() {
assertThat(
new PatternKeywordType()
- .createKeyword(Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$"))
+ .createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
+ Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$")
+ )
.asAssertion()
.isValidFor(Json.createValue("(888)555-1212")),
is(true)
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordTypeTest.java
index f87eb4cb..3fc93b7d 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/basic/TypeKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Assertion;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@@ -35,17 +36,29 @@ class TypeKeywordTypeTest {
@Test
void should_know_his_name() {
- assertThat(new TypeKeywordType().createKeyword(Json.createValue("string")).hasName("type"), is(true));
+ assertThat(
+ new TypeKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string"))
+ .hasName("type"),
+ is(true)
+ );
}
@Test
void should_know_other_names() {
- assertThat(new TypeKeywordType().createKeyword(Json.createValue("string")).hasName("id"), is(false));
+ assertThat(
+ new TypeKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string"))
+ .hasName("id"),
+ is(false)
+ );
}
@Test
void should_use_stringvalue_to_validate_type() {
- final Assertion typeAssertion = new TypeKeywordType().createKeyword(Json.createValue("string")).asAssertion();
+ final Assertion typeAssertion = new TypeKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string"))
+ .asAssertion();
assertThat(typeAssertion.isValidFor(Json.createValue("value")), is(true));
assertThat(typeAssertion.isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(false));
@@ -57,6 +70,7 @@ void should_use_stringvalue_to_validate_type() {
void should_use_arrayvalue_to_validate_type() {
final Assertion typeAssertion = new TypeKeywordType()
.createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
Json.createArrayBuilder().add(Json.createValue("string")).add(Json.createValue("object")).build()
)
.asAssertion();
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordTypeTest.java
index 1118579e..97995832 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/CommentKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -33,6 +34,11 @@ class CommentKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
- assertThat(new CommentKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$comment"), is(true));
+ assertThat(
+ new CommentKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$comment"),
+ is(true)
+ );
}
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordTypeTest.java
index 66910b81..10131d5b 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DefsKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -33,6 +34,11 @@ class DefsKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
- assertThat(new DefsKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$defs"), is(true));
+ assertThat(
+ new DefsKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$defs"),
+ is(true)
+ );
}
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordTypeTest.java
index 4a04213b..1fd68018 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/DynamicRefKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -35,14 +36,17 @@ class DynamicRefKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
assertThat(
- new DynamicRefKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$dynamicRef"),
+ new DynamicRefKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$dynamicRef"),
is(true)
);
}
@Test
void notFinischedYet() {
- final Keyword keyword = new DynamicRefKeywordType().createKeyword(JsonValue.FALSE);
+ final Keyword keyword = new DynamicRefKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE);
assertThat(keyword.hasName("$dynamicRef"), is(true));
assertThat(keyword.hasName("$id"), is(false));
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordTypeTest.java
index 3226a1e5..e9a76126 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/IdKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -33,6 +34,11 @@ class IdKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
- assertThat(new IdKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$id"), is(true));
+ assertThat(
+ new IdKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$id"),
+ is(true)
+ );
}
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordTypeTest.java
index 5f8a1bdf..dbbd8638 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/RefKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -34,12 +35,18 @@ class RefKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
- assertThat(new RefKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$ref"), is(true));
+ assertThat(
+ new RefKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$ref"),
+ is(true)
+ );
}
@Test
void notFinischedYet() {
- final Keyword keyword = new RefKeywordType().createKeyword(JsonValue.FALSE);
+ final Keyword keyword = new RefKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE);
assertThat(keyword.hasName("$ref"), is(true));
assertThat(keyword.hasName("$id"), is(false));
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordTypeTest.java
index 60b77e4c..5f33d354 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/SchemaKeywordTypeTest.java
@@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
@@ -33,6 +34,11 @@ class SchemaKeywordTypeTest {
@Test
void should_create_keyword_with_name() {
- assertThat(new SchemaKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT).hasName("$schema"), is(true));
+ assertThat(
+ new SchemaKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT)
+ .hasName("$schema"),
+ is(true)
+ );
}
}
diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordTypeTest.java
index 45923f04..17a25ab7 100644
--- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordTypeTest.java
+++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/core/VocabularyKeywordTypeTest.java
@@ -27,7 +27,8 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
-import io.github.sebastiantoepfer.jsonschema.core.vocab.core.VocabularyKeywordType;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
+import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition;
import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinitions;
@@ -42,12 +43,17 @@ class VocabularyKeywordTypeTest {
@Test
void should_not_create_keyword_for_non_jsonobject() {
final VocabularyKeywordType keywordType = new VocabularyKeywordType();
- Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(JsonValue.FALSE));
+ final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE);
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> keywordType.createKeyword(schema, JsonValue.FALSE)
+ );
}
@Test
void should_created_keyword_should_know_his_name() {
- final Keyword vocabulary = new VocabularyKeywordType().createKeyword(JsonValue.EMPTY_JSON_OBJECT);
+ final Keyword vocabulary = new VocabularyKeywordType()
+ .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT);
assertThat(vocabulary.hasName("$vocabulary"), is(true));
assertThat(vocabulary.hasName("$id"), is(false));
@@ -58,6 +64,7 @@ void should_create_definitions() {
assertThat(
((VocabularyDefinitions) new VocabularyKeywordType()
.createKeyword(
+ new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
Json
.createObjectBuilder()
.add("http://json-schema.org/test", true)
diff --git a/vocabulary-spi/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/spi/DefaultVocabularyTest.java b/vocabulary-spi/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/spi/DefaultVocabularyTest.java
index f704ff95..b5356049 100644
--- a/vocabulary-spi/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/spi/DefaultVocabularyTest.java
+++ b/vocabulary-spi/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/spi/DefaultVocabularyTest.java
@@ -28,6 +28,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
import jakarta.json.JsonValue;
@@ -76,7 +77,7 @@ public String name() {
}
@Override
- public Keyword createKeyword(final JsonValue value) {
+ public Keyword createKeyword(final JsonSchema schema, final JsonValue value) {
throw new UnsupportedOperationException("Not supported yet.");
}
}