From aed2418b2fdcbe246b231cc883e741b8400373e0 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Thu, 5 Oct 2023 10:26:07 +0200 Subject: [PATCH 1/4] add posibility to retrieve root-schema --- .../jsonschema/JsonSchema.java | 6 +- .../jsonschema/JsonSubSchema.java | 5 ++ .../jsonschema/FakeJsonSchemaFactory.java | 31 +++++---- .../jsonschema/JsonSchemaTest.java | 40 +++++++++++ .../jsonschema/JsonSubSchemaTest.java | 66 +++++++++++++++++++ 5 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSchemaTest.java create mode 100644 api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java index 5d559418..2e2da397 100644 --- a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java +++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java @@ -28,7 +28,11 @@ import java.util.Optional; public interface JsonSchema extends JsonValue { - public Validator validator(); + Validator validator(); Optional keywordByName(String name); + + default JsonSchema rootSchema() { + return this; + } } diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java index 0c4ca96b..d6ef9cbb 100644 --- a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java +++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchema.java @@ -29,4 +29,9 @@ */ public interface JsonSubSchema extends JsonSchema { JsonSchema owner(); + + @Override + default JsonSchema rootSchema() { + return owner().rootSchema(); + } } diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java index f909b7ae..16ae4822 100644 --- a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java @@ -32,21 +32,24 @@ public final class FakeJsonSchemaFactory implements JsonSchemaFactory { @Override public JsonSchema create(final JsonValue schema) { - return new JsonSchema() { - @Override - public Validator validator() { - throw new UnsupportedOperationException("Not supported yet."); - } + return new FakeJsonSchema(); + } + + static class FakeJsonSchema implements JsonSchema { + + @Override + public Validator validator() { + throw new UnsupportedOperationException("Not supported yet."); + } - @Override - public JsonValue.ValueType getValueType() { - throw new UnsupportedOperationException("Not supported yet."); - } + @Override + public Optional keywordByName(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } - @Override - public Optional keywordByName(String name) { - throw new UnsupportedOperationException("Not supported yet."); - } - }; + @Override + public JsonValue.ValueType getValueType() { + throw new UnsupportedOperationException("Not supported yet."); + } } } diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSchemaTest.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSchemaTest.java new file mode 100644 index 00000000..9f14dda8 --- /dev/null +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSchemaTest.java @@ -0,0 +1,40 @@ +/* + * 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; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.sameInstance; + +import io.github.sebastiantoepfer.jsonschema.FakeJsonSchemaFactory.FakeJsonSchema; +import org.junit.jupiter.api.Test; + +class JsonSchemaTest { + + @Test + void should_return_itself_as_root_schema() { + final JsonSchema schema = new FakeJsonSchema(); + assertThat(schema.rootSchema(), is(sameInstance(schema))); + } +} diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java new file mode 100644 index 00000000..f5ac1fa4 --- /dev/null +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java @@ -0,0 +1,66 @@ +/* + * 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; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.sameInstance; + +import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; +import jakarta.json.JsonValue; +import java.util.Optional; +import org.junit.jupiter.api.Test; + +class JsonSubSchemaTest { + + @Test + void should_return_its_owner_as_root() { + final JsonSchema root = new FakeJsonSchemaFactory.FakeJsonSchema(); + assertThat( + new JsonSubSchema() { + @Override + public JsonSchema owner() { + return root; + } + + @Override + public Validator validator() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Optional keywordByName(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public JsonValue.ValueType getValueType() { + throw new UnsupportedOperationException("Not supported yet."); + } + } + .rootSchema(), + is(sameInstance(root)) + ); + } +} From c86c9e50ea43291d3eb785149e665e7efacedc62 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Sun, 3 Dec 2023 12:17:44 +0100 Subject: [PATCH 2/4] add module for api tests --- api/src/test/java/module-info.java | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 api/src/test/java/module-info.java diff --git a/api/src/test/java/module-info.java b/api/src/test/java/module-info.java new file mode 100644 index 00000000..359118ed --- /dev/null +++ b/api/src/test/java/module-info.java @@ -0,0 +1,31 @@ +/* + * 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. + */ + +open module io.github.sebastiantoepfer.jsonschema { + requires jakarta.json; + + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; + requires org.hamcrest; +} From 896b9a8db34962a1f5a7176e398cc9f708d057a5 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Sun, 3 Dec 2023 12:18:41 +0100 Subject: [PATCH 3/4] remove value from createKeyword() --- .../jsonschema/keyword/KeywordType.java | 3 +- .../jsonschema/keyword/KeywordTypeTest.java | 3 +- .../jsonschema/core/DefaultJsonSchema.java | 2 +- .../jsonschema/core/KeywordSearch.java | 3 +- .../jsonschema/core/Keywords.java | 7 +- .../jsonschema/core/UnknowKeywordType.java | 5 +- .../AdditionalPropertiesKeywordType.java | 4 +- .../vocab/applicator/ItemsKeywordType.java | 4 +- .../PatternPropertiesKeywordType.java | 4 +- .../applicator/PrefixItemsKeywordType.java | 3 +- .../applicator/PropertiesKeywordType.java | 4 +- .../core/vocab/core/CommentKeywordType.java | 5 +- .../core/vocab/core/DefsKeywordType.java | 5 +- .../vocab/core/DynamicRefKeywordType.java | 2 +- .../core/vocab/core/IdKeywordType.java | 3 +- .../core/vocab/core/RefKeywordType.java | 3 +- .../core/vocab/core/SchemaKeywordType.java | 3 +- .../vocab/core/VocabularyKeywordType.java | 3 +- .../vocab/validation/EnumKeywordType.java | 4 +- .../ExclusiveMaximumKeywordType.java | 3 +- .../ExclusiveMinimumKeywordType.java | 3 +- .../vocab/validation/MaxItemsKeywordType.java | 4 +- .../validation/MaxLengthKeywordType.java | 3 +- .../vocab/validation/MaximumKeywordType.java | 3 +- .../vocab/validation/MinItemsKeywordType.java | 4 +- .../validation/MinLengthKeywordType.java | 3 +- .../vocab/validation/MinimumKeywordType.java | 3 +- .../validation/MultipleOfKeywordType.java | 3 +- .../vocab/validation/PatternKeywordType.java | 3 +- .../vocab/validation/RequiredKeywordType.java | 4 +- .../vocab/validation/TypeKeywordType.java | 4 +- .../validation/UniqueItemsKeywordType.java | 3 +- .../jsonschema/core/BasicVocabularyTest.java | 8 +- .../AdditionalPropertiesKeywordTypeTest.java | 30 ++++--- .../applicator/ItemsKeywordTypeTest.java | 87 +++++++++++++------ .../PatternPropertiesKeywordTypeTest.java | 74 +++++++++++++--- .../PrefixItemsKeywordTypeTest.java | 67 ++++++++++---- .../applicator/PropertiesKeywordTypeTest.java | 51 ++++++++--- .../vocab/core/CommentKeywordTypeTest.java | 6 +- .../core/vocab/core/DefsKeywordTypeTest.java | 14 ++- .../vocab/core/DynamicRefKeywordTypeTest.java | 11 ++- .../core/vocab/core/IdKeywordTypeTest.java | 21 +++-- .../core/vocab/core/RefKeywordTypeTest.java | 18 ++-- .../vocab/core/SchemaKeywordTypeTest.java | 22 +++-- .../vocab/core/VocabularyKeywordTypeTest.java | 38 ++++---- .../vocab/validation/EnumKeywordTypeTest.java | 27 ++++-- .../ExclusiveMaximumKeywordTypeTest.java | 34 +++++--- .../ExclusiveMinimumKeywordTypeTest.java | 34 +++++--- .../validation/MaxItemsKeywordTypeTest.java | 25 ++++-- .../validation/MaxLengthKeywordTypeTest.java | 31 +++++-- .../validation/MaximumKeywordTypeTest.java | 34 +++++--- .../validation/MinItemsKeywordTypeTest.java | 25 ++++-- .../validation/MinLengthKeywordTypeTest.java | 33 ++++--- .../validation/MinimumKeywordTypeTest.java | 34 +++++--- .../validation/MultipleOfKeywordTypeTest.java | 35 ++++++-- .../validation/PatternKeywordTypeTest.java | 37 +++++--- .../validation/RequiredKeywordTypeTest.java | 32 +++++-- .../vocab/validation/TypeKeywordTypeTest.java | 31 +++++-- .../UniqueItemsKeywordTypeTest.java | 38 +++++--- .../vocabulary/spi/DefaultVocabularyTest.java | 3 +- 60 files changed, 705 insertions(+), 308 deletions(-) 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 ec84aba6..9cfe1729 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 @@ -24,7 +24,6 @@ package io.github.sebastiantoepfer.jsonschema.keyword; import io.github.sebastiantoepfer.jsonschema.JsonSchema; -import jakarta.json.JsonValue; import java.util.Objects; public interface KeywordType { @@ -34,5 +33,5 @@ default boolean hasName(String name) { String name(); - Keyword createKeyword(JsonSchema schema, JsonValue value); + Keyword createKeyword(JsonSchema schema); } 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 af5e8364..124f6e1c 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 @@ -27,7 +27,6 @@ import static org.hamcrest.Matchers.is; import io.github.sebastiantoepfer.jsonschema.JsonSchema; -import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; class KeywordTypeTest { @@ -46,7 +45,7 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { throw new UnsupportedOperationException("Not supported yet."); } } 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 c69923c5..085a8534 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 @@ -76,7 +76,7 @@ private Collection vocabulary() { } private Stream keywords() { - return asJsonObject().entrySet().stream().map(property -> keywords.createKeywordFor(this, property)); + return asJsonObject().keySet().stream().map(propertyName -> keywords.createKeywordFor(this, propertyName)); } private Optional> asContraint(final Keyword keyword) { 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 542c4127..5f597514 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 @@ -29,6 +29,7 @@ import java.util.Objects; import java.util.Optional; +@Deprecated final class KeywordSearch { private final KeywordType keywordType; @@ -40,6 +41,6 @@ public KeywordSearch(final KeywordType keywordType) { public Optional searchForKeywordIn(final JsonSchema schema) { return Optional .ofNullable(schema.asJsonObject().get(keywordType.name())) - .map(keywordValue -> keywordType.createKeyword(schema, keywordValue)); + .map(keywordValue -> keywordType.createKeyword(schema)); } } 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 558ec122..9cf20717 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 @@ -33,7 +33,6 @@ import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.ValidationVocabulary; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition; -import jakarta.json.JsonValue; import java.net.URI; import java.util.ArrayDeque; import java.util.Collection; @@ -85,13 +84,13 @@ public Keywords(final Collection vocabDefs) { ); } - public Keyword createKeywordFor(final JsonSchema schema, final Map.Entry property) { + public Keyword createKeywordFor(final JsonSchema schema, final String propertyName) { return vocabularies .stream() - .map(vocab -> vocab.findKeywordTypeByName(property.getKey())) + .map(vocab -> vocab.findKeywordTypeByName(propertyName)) .flatMap(Optional::stream) .findFirst() - .map(keywordType -> keywordType.createKeyword(schema, property.getValue())) + .map(keywordType -> keywordType.createKeyword(schema)) .orElseThrow(); } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/UnknowKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/UnknowKeywordType.java index 26d02923..44af5782 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/UnknowKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/UnknowKeywordType.java @@ -27,7 +27,6 @@ import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.StaticAnnotation; -import jakarta.json.JsonValue; import java.util.Objects; final class UnknowKeywordType implements KeywordType { @@ -44,7 +43,7 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new StaticAnnotation(name(), value); + public Keyword createKeyword(final JsonSchema schema) { + return new StaticAnnotation(name(), schema.asJsonObject().get(name())); } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordType.java index 0f2b5b40..00ef8363 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordType.java @@ -52,8 +52,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new AdditionalPropertiesKeyword(schema, value); + public Keyword createKeyword(final JsonSchema schema) { + return new AdditionalPropertiesKeyword(schema, schema.asJsonObject().get(name())); } private class AdditionalPropertiesKeyword implements Applicator, Annotation { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java index 1c230e7f..2a238f55 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java @@ -48,8 +48,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new ItemsKeyword(schema, JsonSchemas.load(value)); + public Keyword createKeyword(final JsonSchema schema) { + return new ItemsKeyword(schema, JsonSchemas.load(schema.asJsonObject().get(name()))); } private class ItemsKeyword implements Applicator, Annotation, JsonSubSchema { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordType.java index 303be0d9..a0085d88 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordType.java @@ -50,8 +50,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new PatternPropertiesKeyword(value.asJsonObject()); + public Keyword createKeyword(final JsonSchema schema) { + return new PatternPropertiesKeyword(schema.asJsonObject().getJsonObject(name())); } private class PatternPropertiesKeyword implements Applicator, Annotation { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordType.java index fdafd1f8..02efb99f 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordType.java @@ -49,7 +49,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.ARRAY.isInstance(value)) { return new PrefixItemsKeyword(value.asJsonArray()); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordType.java index a62813e2..edd48814 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordType.java @@ -48,8 +48,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new PropertiesKeyword(value.asJsonObject()); + public Keyword createKeyword(final JsonSchema schema) { + return new PropertiesKeyword(schema.asJsonObject().getJsonObject(name())); } private class PropertiesKeyword implements Applicator, Annotation { 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 ce060338..8d857d47 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 @@ -27,7 +27,6 @@ import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.StaticAnnotation; -import jakarta.json.JsonValue; /** * @@ -41,7 +40,7 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new StaticAnnotation(name(), value); + public Keyword createKeyword(final JsonSchema schema) { + return new StaticAnnotation(name(), schema.asJsonObject().get(name())); } } 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 1cf89dd6..9f3a7325 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 @@ -28,7 +28,6 @@ import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.ReservedLocation; -import jakarta.json.JsonValue; import java.util.Objects; /** @@ -43,8 +42,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - if (InstanceType.OBJECT.isInstance(value)) { + public Keyword createKeyword(final JsonSchema schema) { + if (InstanceType.OBJECT.isInstance(schema.asJsonObject().get(name()))) { return new DefsKeyword(); } else { throw new IllegalArgumentException("must be an object!"); 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 49821a6d..998b052d 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 @@ -42,7 +42,7 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { 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 59674c01..913840f4 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 @@ -45,7 +45,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.STRING.isInstance(value)) { return new IdKeyword((JsonString) value); } else { 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 1dd63936..a1bfd8d6 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 @@ -50,7 +50,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.STRING.isInstance(value)) { return new RefKeyword(schema, (JsonString) value); } else { 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 e84d57af..76645f4d 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 @@ -45,7 +45,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.STRING.isInstance(value)) { return new SchemaKeyword((JsonString) value); } else { 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 c7344eec..e701e55e 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 @@ -48,7 +48,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get((name())); final Keyword result; if (InstanceType.OBJECT.isInstance(value)) { result = new VocabularyKeyword(value); diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordType.java index 7cbaf7d8..7f207587 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordType.java @@ -44,8 +44,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new EnumKeyword(value.asJsonArray()); + public Keyword createKeyword(final JsonSchema schema) { + return new EnumKeyword(schema.asJsonObject().getJsonArray(name())); } private class EnumKeyword implements Assertion { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordType.java index 233790fa..6132b617 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.NUMBER.isInstance(value)) { return new ExclusiveMaximumKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordType.java index e59ede7b..f708b5ce 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.NUMBER.isInstance(value)) { return new ExclusiveMinimumKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordType.java index c8e482b3..0f3d3c68 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordType.java @@ -40,8 +40,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new MaxItemsKeyword((JsonNumber) value); + public Keyword createKeyword(final JsonSchema schema) { + return new MaxItemsKeyword(schema.asJsonObject().getJsonNumber(name())); } private class MaxItemsKeyword implements Assertion { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordType.java index ca0b1e36..dee8ce15 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.INTEGER.isInstance(value)) { return new MaxLengthKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordType.java index d95d7376..7e95c9b8 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.NUMBER.isInstance(value)) { return new MaximumKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordType.java index 3b09a884..35f9a395 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordType.java @@ -40,8 +40,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new MinItemsKeyword((JsonNumber) value); + public Keyword createKeyword(final JsonSchema schema) { + return new MinItemsKeyword(schema.asJsonObject().getJsonNumber(name())); } private class MinItemsKeyword implements Assertion { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordType.java index f503f0f8..b61164d4 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.INTEGER.isInstance(value)) { return new MinLengthKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordType.java index 21c0baa1..73450168 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.NUMBER.isInstance(value)) { return new MinimumKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java index 6d3ff4d6..3c46a711 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.NUMBER.isInstance(value)) { return new MultipleOfKeyword((JsonNumber) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordType.java index 877b0a2f..f5021565 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordType.java @@ -41,7 +41,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.STRING.isInstance(value)) { return new PatternKeyword((JsonString) value); } else { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordType.java index 1b4cafad..70c2c696 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordType.java @@ -42,8 +42,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new RequiredKeyword(value.asJsonArray()); + public Keyword createKeyword(final JsonSchema schema) { + return new RequiredKeyword(schema.asJsonObject().getJsonArray(name())); } private class RequiredKeyword implements Assertion { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordType.java index 05b2212c..9daae6b0 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordType.java @@ -46,8 +46,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { - return new TypeKeyword(value); + public Keyword createKeyword(final JsonSchema schema) { + return new TypeKeyword(schema.asJsonObject().get(name())); } private final class TypeKeyword implements Assertion { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java index 892ca6d3..a58760e4 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordType.java @@ -45,7 +45,8 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { + final JsonValue value = schema.asJsonObject().get(name()); if (InstanceType.BOOLEAN.isInstance(value)) { return new UniqueItemsKeyword(value.getValueType() == JsonValue.ValueType.TRUE); } else { diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/BasicVocabularyTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/BasicVocabularyTest.java index 869180d6..8f5edbca 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/BasicVocabularyTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/BasicVocabularyTest.java @@ -27,9 +27,8 @@ import static org.hamcrest.Matchers.is; import com.github.npathai.hamcrestopt.OptionalMatchers; -import io.github.sebastiantoepfer.jsonschema.core.BasicVocabulary; -import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; +import jakarta.json.Json; import jakarta.json.JsonValue; import java.net.URI; import org.junit.jupiter.api.Test; @@ -58,7 +57,10 @@ void should_return_the_custom_annotation_for_unknow_keyword() { new BasicVocabulary() .findKeywordTypeByName("unknow") .map(keywordType -> - keywordType.createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE) + keywordType.createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("unknow", JsonValue.FALSE).build()) + ) ) .map(keyword -> keyword.hasName("unknow")), OptionalMatchers.isPresentAndIs(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordTypeTest.java index aa9f2d21..262d5bd2 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/AdditionalPropertiesKeywordTypeTest.java @@ -38,7 +38,10 @@ class AdditionalPropertiesKeywordTypeTest { @Test void should_know_his_name() { final Keyword keyword = new AdditionalPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("additionalProperties", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(keyword.hasName("additionalProperties"), is(true)); assertThat(keyword.hasName("test"), is(false)); @@ -54,9 +57,9 @@ void should_be_valid_for_non_objects() { Json .createObjectBuilder() .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .add("additionalProperties", JsonValue.FALSE) .build() - ), - JsonValue.FALSE + ) ) .asApplicator() .applyTo(JsonValue.EMPTY_JSON_ARRAY), @@ -74,9 +77,9 @@ void should_not_valid_if_no_additionals_are_allow() { Json .createObjectBuilder() .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .add("additionalProperties", JsonValue.FALSE) .build() - ), - JsonValue.FALSE + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).add("foo", 1).build()), @@ -94,9 +97,9 @@ void should_valid_if_additionals_are_allow() { Json .createObjectBuilder() .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .add("additionalProperties", JsonValue.TRUE) .build() - ), - JsonValue.TRUE + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).add("foo", 1).build()), @@ -114,9 +117,9 @@ void should_valid_if_no_additionals_are_allow_and_no_additionals_their() { Json .createObjectBuilder() .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .add("additionalProperties", JsonValue.FALSE) .build() - ), - JsonValue.FALSE + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -128,7 +131,10 @@ void should_valid_if_no_additionals_are_allow_and_no_additionals_their() { void should_be_an_applicator_and_an_annotation() { assertThat( new AdditionalPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.TRUE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("additionalProperties", JsonValue.TRUE).build()) + ) .categories(), containsInAnyOrder(Keyword.KeywordCategory.APPLICATOR, Keyword.KeywordCategory.ANNOTATION) ); @@ -144,9 +150,9 @@ void should_return_propertynames_which_will_be_validated() { Json .createObjectBuilder() .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .add("additionalProperties", JsonValue.TRUE) .build() - ), - JsonValue.TRUE + ) ) .asAnnotation() .valueFor(Json.createObjectBuilder().add("test", 1).add("foo", 1).build()) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java index af44eb12..8814f8f3 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java @@ -28,6 +28,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.sameInstance; import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; @@ -35,7 +36,6 @@ 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 { @@ -43,7 +43,10 @@ class ItemsKeywordTypeTest { @Test void should_know_his_name() { final Keyword items = new ItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("items", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(items.hasName("items"), is(true)); assertThat(items.hasName("test"), is(false)); @@ -54,8 +57,13 @@ 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() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("items", Json.createObjectBuilder().add("type", "number")) + .build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add(1).add("invalid").add(2).build()), @@ -68,8 +76,13 @@ void should_be_valid_if_all_items_match_schema() { assertThat( new ItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("type", "number").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("items", Json.createObjectBuilder().add("type", "number")) + .build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add(1).add(2).build()), @@ -79,11 +92,9 @@ void should_be_valid_if_all_items_match_schema() { @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)) - ); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("items", JsonValue.TRUE).build()); + assertThat(((JsonSubSchema) new ItemsKeywordType().createKeyword(schema)).owner(), is(sameInstance(schema))); } @Test @@ -91,8 +102,8 @@ void should_return_his_json_valuetype() { assertThat( ((JsonSubSchema) new ItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - JsonValue.EMPTY_JSON_OBJECT + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("items", JsonValue.EMPTY_JSON_OBJECT).build()) )).getValueType(), is(JsonValue.ValueType.OBJECT) ); @@ -102,7 +113,10 @@ void should_return_his_json_valuetype() { void should_be_applicator_and_annotation() { assertThat( new ItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("items", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .categories(), contains(Keyword.KeywordCategory.APPLICATOR, Keyword.KeywordCategory.ANNOTATION) ); @@ -112,7 +126,10 @@ void should_be_applicator_and_annotation() { void should_produces_true_if_is_applied_to_any_instance() { assertThat( new ItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("items", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .asAnnotation() .valueFor(Json.createArrayBuilder().add(1).build()), is(JsonValue.TRUE) @@ -124,8 +141,13 @@ void should_find_know_keyword() { assertThat( ((JsonSubSchema) new ItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("type", "string").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("items", Json.createObjectBuilder().add("type", "string")) + .build() + ) )).keywordByName("type"), isPresent() ); @@ -136,8 +158,13 @@ void should_retrun_empty_for_non_existing_keyword() { assertThat( ((JsonSubSchema) new ItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("type", "string").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("items", Json.createObjectBuilder().add("type", "string")) + .build() + ) )).keywordByName("properties"), isEmpty() ); @@ -150,9 +177,12 @@ void should_return_false_if_not_applies_to_any_item() { .createKeyword( new DefaultJsonSchemaFactory() .create( - Json.createObjectBuilder().add("prefixItems", Json.createArrayBuilder().add(true)).build() - ), - JsonValue.FALSE + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(true)) + .add("items", JsonValue.FALSE) + .build() + ) ) .asAnnotation() .valueFor(Json.createArrayBuilder().add(1).build()), @@ -170,9 +200,9 @@ void should_be_valid_if_invaliditem_is_already_checked_by_prefixItems() { Json .createObjectBuilder() .add("prefixItems", Json.createArrayBuilder().add(true).add(true)) + .add("items", Json.createObjectBuilder().add("type", "integer")) .build() - ), - Json.createObjectBuilder().add("type", "integer").build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add("1").add("2").add(1).build()), @@ -187,9 +217,12 @@ void should_be_invalid_if_invaliditem_is_not_already_checked_by_prefixItems() { .createKeyword( new DefaultJsonSchemaFactory() .create( - Json.createObjectBuilder().add("prefixItems", Json.createArrayBuilder().add(true)).build() - ), - Json.createObjectBuilder().add("type", "integer").build() + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(true)) + .add("items", Json.createObjectBuilder().add("type", "integer")) + .build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add("1").add("2").add(1).build()), diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordTypeTest.java index 7c498208..6dece1d6 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PatternPropertiesKeywordTypeTest.java @@ -40,7 +40,10 @@ class PatternPropertiesKeywordTypeTest { @Test void should_know_his_name() { final Keyword keyword = new PatternPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("patternProperties", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(keyword.hasName("patternProperties"), is(true)); assertThat(keyword.hasName("test"), is(false)); @@ -50,7 +53,12 @@ void should_know_his_name() { void should_be_an_applicator_and_an_annotation() { assertThat( new PatternPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create( + Json.createObjectBuilder().add("patternProperties", JsonValue.EMPTY_JSON_OBJECT).build() + ) + ) .categories(), containsInAnyOrder(Keyword.KeywordCategory.APPLICATOR, Keyword.KeywordCategory.ANNOTATION) ); @@ -60,7 +68,12 @@ void should_be_an_applicator_and_an_annotation() { void should_be_valid_for_non_object() { assertThat( new PatternPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create( + Json.createObjectBuilder().add("patternProperties", JsonValue.EMPTY_JSON_OBJECT).build() + ) + ) .asApplicator() .applyTo(JsonValue.FALSE), is(true) @@ -71,7 +84,12 @@ void should_be_valid_for_non_object() { void should_be_valid_for_empty_object() { assertThat( new PatternPropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create( + Json.createObjectBuilder().add("patternProperties", JsonValue.EMPTY_JSON_OBJECT).build() + ) + ) .asApplicator() .applyTo(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -83,8 +101,13 @@ void should_be_valid_if_properties_applies_to_his_schema() { assertThat( new PatternPropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("t.st", JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("patternProperties", Json.createObjectBuilder().add("t.st", JsonValue.TRUE)) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -97,8 +120,13 @@ void should_be_invalid_if_properties_not_applies_to_his_schema() { assertThat( new PatternPropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("t.st", JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("patternProperties", Json.createObjectBuilder().add("t.st", JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -116,8 +144,16 @@ void should_be_invalid_if_one_schema_doesn_apply() { assertThat( new PatternPropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("t.st", JsonValue.TRUE).add("t.*", JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add( + "patternProperties", + Json.createObjectBuilder().add("t.st", JsonValue.TRUE).add("t.*", JsonValue.FALSE) + ) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -130,8 +166,13 @@ void should_be_valid_if_properties_not_covered() { assertThat( new PatternPropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("t.st", JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("patternProperties", Json.createObjectBuilder().add("t.st", JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("foo", 1).build()), @@ -144,8 +185,13 @@ void should_return_the_matching_property_names() { assertThat( new PatternPropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("f.o", JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("patternProperties", Json.createObjectBuilder().add("f.o", JsonValue.TRUE)) + .build() + ) ) .asAnnotation() .valueFor( diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordTypeTest.java index 4dc81dfd..2417a197 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PrefixItemsKeywordTypeTest.java @@ -42,8 +42,13 @@ class PrefixItemsKeywordTypeTest { void should_know_his_name() { final Keyword items = new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.TRUE)) + .build() + ) ); assertThat(items.hasName("prefixItems"), is(true)); @@ -53,12 +58,10 @@ void should_know_his_name() { @Test void should_not_be_createbale_from_non_array() { final KeywordType keywordType = new PrefixItemsKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("prefixItems", JsonValue.EMPTY_JSON_OBJECT).build()); - assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.EMPTY_JSON_OBJECT) - ); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test @@ -66,8 +69,13 @@ void should_return_zero_as_value() { assertThat( new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.TRUE)) + .build() + ) ) .asAnnotation() .valueFor(Json.createArrayBuilder().add(1).add(2).build()), @@ -80,8 +88,13 @@ void should_retrun_true_if_is_applies_to_all_values() { assertThat( new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.TRUE).add(JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.TRUE).add(JsonValue.TRUE)) + .build() + ) ) .asAnnotation() .valueFor(Json.createArrayBuilder().add(1).add(2).build()), @@ -94,8 +107,13 @@ void should_be_valid_for_non_arrays() { assertThat( new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(Json.createValue(1)), @@ -108,8 +126,13 @@ void should_be_valid_if_first_item_match_schema() { assertThat( new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.TRUE)) + .build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add(1).build()), @@ -122,8 +145,13 @@ void should_be_invalid_if_second_item_does_not_match_schema() { assertThat( new PrefixItemsKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(JsonValue.TRUE).add(JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(JsonValue.TRUE).add(JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(Json.createArrayBuilder().add(1).add(3).build()), @@ -135,7 +163,10 @@ void should_be_invalid_if_second_item_does_not_match_schema() { void should_be_applicator_and_annotation() { assertThat( new PrefixItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_ARRAY) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("prefixItems", JsonValue.EMPTY_JSON_ARRAY).build()) + ) .categories(), containsInAnyOrder(Keyword.KeywordCategory.APPLICATOR, Keyword.KeywordCategory.ANNOTATION) ); diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordTypeTest.java index 1991a32d..efa34fb4 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/PropertiesKeywordTypeTest.java @@ -39,7 +39,10 @@ class PropertiesKeywordTypeTest { @Test void should_be_know_his_name() { final Keyword keyword = new PropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("properties", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(keyword.hasName("properties"), is(true)); assertThat(keyword.hasName("test"), is(false)); @@ -49,7 +52,10 @@ void should_be_know_his_name() { void should_be_an_applicator_and_annotation() { assertThat( new PropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("properties", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .categories(), Matchers.containsInAnyOrder(Keyword.KeywordCategory.APPLICATOR, Keyword.KeywordCategory.ANNOTATION) ); @@ -59,7 +65,10 @@ void should_be_an_applicator_and_annotation() { void should_be_valid_for_non_objects() { assertThat( new PropertiesKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("properties", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .asApplicator() .applyTo(JsonValue.EMPTY_JSON_ARRAY), is(true) @@ -71,8 +80,13 @@ void should_be_valid_if_properties_applies_to_his_schema() { assertThat( new PropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("test", JsonValue.TRUE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -85,8 +99,13 @@ void should_be_invalid_if_properties_not_applies_to_his_schema() { assertThat( new PropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("test", JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("properties", Json.createObjectBuilder().add("test", JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(Json.createObjectBuilder().add("test", 1).build()), @@ -99,8 +118,13 @@ void should_be_valid_for_empty_objects() { assertThat( new PropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("test", JsonValue.FALSE).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("properties", Json.createObjectBuilder().add("test", JsonValue.FALSE)) + .build() + ) ) .asApplicator() .applyTo(JsonValue.EMPTY_JSON_OBJECT), @@ -113,8 +137,13 @@ void should_return_all_matched_propertynames() { assertThat( new PropertiesKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createObjectBuilder().add("test", true).add("foo", true).build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("properties", Json.createObjectBuilder().add("test", true).add("foo", true)) + .build() + ) ) .asAnnotation() .valueFor(Json.createObjectBuilder().add("foo", 1).build()) 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 97995832..8c098ee8 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 @@ -27,6 +27,7 @@ import static org.hamcrest.Matchers.is; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; +import jakarta.json.Json; import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; @@ -36,7 +37,10 @@ class CommentKeywordTypeTest { void should_create_keyword_with_name() { assertThat( new CommentKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$comment", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .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 1343f69e..d59c12be 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 @@ -27,8 +27,11 @@ 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 io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; +import jakarta.json.Json; import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; @@ -36,15 +39,20 @@ class DefsKeywordTypeTest { @Test void should_not_be_creatable_from_non_objects() { - final DefsKeywordType schema = new DefsKeywordType(); + final KeywordType defs = new DefsKeywordType(); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$defs", JsonValue.FALSE).build()); - assertThrows(IllegalArgumentException.class, () -> schema.createKeyword(null, JsonValue.FALSE)); + assertThrows(IllegalArgumentException.class, () -> defs.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword defs = new DefsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$defs", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(defs.hasName("$defs"), is(true)); assertThat(defs.hasName("test"), is(false)); 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 1fd68018..e7c7ef52 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 @@ -28,6 +28,7 @@ import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; +import jakarta.json.Json; import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; @@ -37,7 +38,10 @@ class DynamicRefKeywordTypeTest { void should_create_keyword_with_name() { assertThat( new DynamicRefKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$dynamicRef", JsonValue.EMPTY_JSON_OBJECT).build()) + ) .hasName("$dynamicRef"), is(true) ); @@ -46,7 +50,10 @@ void should_create_keyword_with_name() { @Test void notFinischedYet() { final Keyword keyword = new DynamicRefKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$dynamicRef", JsonValue.FALSE).build()) + ); 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 9042615d..f61103ae 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 @@ -27,6 +27,7 @@ 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; @@ -38,15 +39,20 @@ class IdKeywordTypeTest { @Test void should_not_be_creatable_from_non_string() { - final IdKeywordType schema = new IdKeywordType(); + final IdKeywordType keyword = new IdKeywordType(); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$id", JsonValue.FALSE).build()); - assertThrows(IllegalArgumentException.class, () -> schema.createKeyword(null, JsonValue.FALSE)); + assertThrows(IllegalArgumentException.class, () -> keyword.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword id = new IdKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("/test")); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$id", Json.createValue("/test")).build()) + ); assertThat(id.hasName("$id"), is(true)); assertThat(id.hasName("test"), is(false)); @@ -57,8 +63,13 @@ void should_retun_his_uri() { assertThat( new IdKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createValue("https://json-schema.org/draft/2020-12/schema") + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("$id", Json.createValue("https://json-schema.org/draft/2020-12/schema")) + .build() + ) ) .asIdentifier() .asUri(), 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 004ea800..29157f3f 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 @@ -39,14 +39,18 @@ class RefKeywordTypeTest { @Test void should_be_not_createbale_from_non_string() { final RefKeywordType keywordType = new RefKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, JsonValue.TRUE)); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$ref", JsonValue.TRUE).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword ref = new RefKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("#")); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$ref", Json.createValue("#")).build()) + ); assertThat(ref.hasName("$ref"), is(true)); assertThat(ref.hasName("test"), is(false)); @@ -66,9 +70,9 @@ void should_use_local_referenced_schema_for_validation() { .createObjectBuilder() .add("positiveInteger", Json.createObjectBuilder().add("type", "integer")) ) + .add("$ref", Json.createValue("#/$defs/positiveInteger")) .build() - ), - Json.createValue("#/$defs/positiveInteger") + ) ); assertThat(keyword.asApplicator().applyTo(Json.createValue(1L)), is(true)); @@ -89,9 +93,9 @@ void should_use_remote_referenced_schema_for_validation() { .createObjectBuilder() .add("positiveInteger", Json.createObjectBuilder().add("type", "integer")) ) + .add("$ref", Json.createValue("#/$defs/positiveInteger")) .build() - ), - Json.createValue("#/$defs/positiveInteger") + ) ); assertThat(keyword.asApplicator().applyTo(Json.createValue(1L)), is(true)); 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 19f6198e..deaf0590 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 @@ -27,6 +27,7 @@ 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; @@ -38,15 +39,19 @@ class SchemaKeywordTypeTest { @Test void should_not_be_creatable_from_non_string() { - final SchemaKeywordType schema = new SchemaKeywordType(); - - assertThrows(IllegalArgumentException.class, () -> schema.createKeyword(null, JsonValue.FALSE)); + final SchemaKeywordType keywordType = new SchemaKeywordType(); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$schema", JsonValue.FALSE).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword schema = new SchemaKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("/test")); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$schema", Json.createValue("/test")).build()) + ); assertThat(schema.hasName("$schema"), is(true)); assertThat(schema.hasName("test"), is(false)); @@ -57,8 +62,13 @@ void should_retun_his_uri() { assertThat( new SchemaKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createValue("https://json-schema.org/draft/2020-12/schema") + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("$schema", Json.createValue("https://json-schema.org/draft/2020-12/schema")) + .build() + ) ) .asIdentifier() .asUri(), 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 17a25ab7..776c80ca 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,6 @@ import static org.hamcrest.Matchers.containsInAnyOrder; 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 io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition; @@ -35,25 +34,17 @@ import jakarta.json.Json; import jakarta.json.JsonValue; import java.net.URI; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class VocabularyKeywordTypeTest { - @Test - void should_not_create_keyword_for_non_jsonobject() { - final VocabularyKeywordType keywordType = new VocabularyKeywordType(); - 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(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_OBJECT); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("$vocabulary", JsonValue.EMPTY_JSON_OBJECT).build()) + ); assertThat(vocabulary.hasName("$vocabulary"), is(true)); assertThat(vocabulary.hasName("$id"), is(false)); @@ -64,16 +55,23 @@ void should_create_definitions() { assertThat( ((VocabularyDefinitions) new VocabularyKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json - .createObjectBuilder() - .add("http://json-schema.org/test", true) - .add("http://openapi.org/test", false) - .build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add( + "$vocabulary", + Json + .createObjectBuilder() + .add("https://json-schema.org/draft/2020-12/vocab/core", true) + .add("http://openapi.org/test", false) + ) + .build() + ) )).definitions() .toList(), containsInAnyOrder( - new VocabularyDefinition(URI.create("http://json-schema.org/test"), true), + new VocabularyDefinition(URI.create("https://json-schema.org/draft/2020-12/vocab/core"), true), new VocabularyDefinition(URI.create("http://openapi.org/test"), false) ) ); diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordTypeTest.java index 1cd72f04..6e46307a 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/EnumKeywordTypeTest.java @@ -37,7 +37,10 @@ class EnumKeywordTypeTest { @Test void should_know_his_name() { final Keyword enumKeyword = new EnumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_ARRAY); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("enum", JsonValue.EMPTY_JSON_ARRAY).build()) + ); assertThat(enumKeyword.hasName("enum"), is(true)); assertThat(enumKeyword.hasName("test"), is(false)); @@ -48,8 +51,13 @@ void should_valid_for_string_value_which_is_in_array() { assertThat( new EnumKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add("TEST").add("VALID").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("enum", Json.createArrayBuilder().add("TEST").add("VALID")) + .build() + ) ) .asAssertion() .isValidFor(Json.createValue("TEST")), @@ -62,8 +70,13 @@ void should_be_invalid_for_number_which_is_not_in_array() { assertThat( new EnumKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add("TEST").add("VALID").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("enum", Json.createArrayBuilder().add("TEST").add("VALID")) + .build() + ) ) .asAssertion() .isValidFor(Json.createValue(2)), @@ -76,8 +89,8 @@ void should_be_valid_for_decimal_without_scale_if_number_is_valid() { assertThat( new EnumKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add(1).build() + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("enum", Json.createArrayBuilder().add(1)).build()) ) .asAssertion() .isValidFor(Json.createValue(1.0)), diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordTypeTest.java index 3beab264..9a3fcd2a 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMaximumKeywordTypeTest.java @@ -28,7 +28,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.ExclusiveMaximumKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -40,7 +39,10 @@ class ExclusiveMaximumKeywordTypeTest { @Test void should_know_his_name() { final Keyword maximum = new ExclusiveMaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", Json.createValue(1)).build()) + ); assertThat(maximum.hasName("exclusiveMaximum"), is(true)); assertThat(maximum.hasName("test"), is(false)); @@ -49,18 +51,19 @@ void should_know_his_name() { @Test void should_not_becreatable_with_non_number() { final ExclusiveMaximumKeywordType keywordType = new ExclusiveMaximumKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - Assertions.assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.FALSE) - ); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", JsonValue.FALSE).build()); + Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_non_number_values() { assertThat( new ExclusiveMaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -71,7 +74,10 @@ void should_be_valid_for_non_number_values() { void should_be_invalid_for_greater_numbers() { assertThat( new ExclusiveMaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(11)), is(false) @@ -82,7 +88,10 @@ void should_be_invalid_for_greater_numbers() { void should_be_invalid_for_equals_numbers() { assertThat( new ExclusiveMaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(10)), is(false) @@ -93,7 +102,10 @@ void should_be_invalid_for_equals_numbers() { void shhould_be_valid_for_smaller_numbers() { assertThat( new ExclusiveMaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMaximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(9)), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordTypeTest.java index fdfff96d..c32da113 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/ExclusiveMinimumKeywordTypeTest.java @@ -28,7 +28,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.ExclusiveMinimumKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -40,7 +39,10 @@ class ExclusiveMinimumKeywordTypeTest { @Test void should_know_his_name() { final Keyword minimum = new ExclusiveMinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", Json.createValue(1)).build()) + ); assertThat(minimum.hasName("exclusiveMinimum"), is(true)); assertThat(minimum.hasName("test"), is(false)); @@ -49,18 +51,19 @@ void should_know_his_name() { @Test void should_not_becreatable_with_non_number() { final ExclusiveMinimumKeywordType keywordType = new ExclusiveMinimumKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - Assertions.assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.FALSE) - ); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", JsonValue.FALSE).build()); + Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_non_number_values() { assertThat( new ExclusiveMinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -71,7 +74,10 @@ void should_be_valid_for_non_number_values() { void should_be_invalid_for_smaller_numbers() { assertThat( new ExclusiveMinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(-1)), is(false) @@ -82,7 +88,10 @@ void should_be_invalid_for_smaller_numbers() { void should_be_invalid_for_equals_numbers() { assertThat( new ExclusiveMinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(0)), is(false) @@ -93,7 +102,10 @@ void should_be_invalid_for_equals_numbers() { void shhould_be_valid_for_greater_numbers() { assertThat( new ExclusiveMinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("exclusiveMinimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(1)), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordTypeTest.java index 82301959..4c8a6c97 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxItemsKeywordTypeTest.java @@ -37,7 +37,10 @@ class MaxItemsKeywordTypeTest { @Test void should_know_his_name() { final Keyword keyword = new MaxItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxItems", Json.createValue(1)).build()) + ); assertThat(keyword.hasName("maxItems"), is(true)); assertThat(keyword.hasName("test"), is(false)); @@ -47,7 +50,10 @@ void should_know_his_name() { void should_be_valid_for_non_arrays() { assertThat( new MaxItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxItems", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -58,7 +64,10 @@ void should_be_valid_for_non_arrays() { void should_be_valid_for_array_with_same_size() { assertThat( new MaxItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxItems", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add(1).add(2).build()), is(true) @@ -69,7 +78,10 @@ void should_be_valid_for_array_with_same_size() { void should_be_valid_for_array_with_smaller_size() { assertThat( new MaxItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxItems", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add(1).build()), is(true) @@ -80,7 +92,10 @@ void should_be_valid_for_array_with_smaller_size() { void should_be_invalid_for_array_with_greather_size() { assertThat( new MaxItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxItems", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add(1).add(2).add(3).build()), is(false) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordTypeTest.java index 34ca837a..ea4d7d92 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaxLengthKeywordTypeTest.java @@ -31,7 +31,6 @@ import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; -import jakarta.json.JsonNumber; import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; @@ -39,16 +38,18 @@ class MaxLengthKeywordTypeTest { @Test void should_not_be_createbale_with_non_integer() { - final JsonNumber value = Json.createValue(12.3); final MinLengthKeywordType keywordType = new MinLengthKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, value)); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxLength", 12.3).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword keyword = new MaxLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("maxLength", 1).build()) + ); assertThat(keyword.hasName("test"), is(false)); assertThat(keyword.hasName("maxLength"), is(true)); @@ -58,7 +59,10 @@ void should_know_his_name() { void should_be_valid_for_non_string_values() { assertThat( new MaxLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_ARRAY), is(true) @@ -69,7 +73,10 @@ void should_be_valid_for_non_string_values() { void should_be_invalid_for_longer_string() { assertThat( new MaxLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("1234")), is(false) @@ -80,7 +87,10 @@ void should_be_invalid_for_longer_string() { void should_be_valid_for_string_with_length_is_equal() { assertThat( new MaxLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("12")), is(true) @@ -91,7 +101,10 @@ void should_be_valid_for_string_with_length_is_equal() { void should_ne_valid_for_string_with_is_shorter() { assertThat( new MaxLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maxLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("1")), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordTypeTest.java index e8ccbc6a..438439db 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MaximumKeywordTypeTest.java @@ -28,7 +28,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.MaximumKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -40,7 +39,10 @@ class MaximumKeywordTypeTest { @Test void should_know_his_name() { final Keyword maximum = new MaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", Json.createValue(1)).build()) + ); assertThat(maximum.hasName("maximum"), is(true)); assertThat(maximum.hasName("test"), is(false)); @@ -49,18 +51,19 @@ void should_know_his_name() { @Test void should_not_becreatable_with_non_number() { final MaximumKeywordType keywordType = new MaximumKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - Assertions.assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.FALSE) - ); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", JsonValue.FALSE).build()); + Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_non_number_values() { assertThat( new MaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -71,7 +74,10 @@ void should_be_valid_for_non_number_values() { void should_be_invalid_for_greater_numbers() { assertThat( new MaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(11)), is(false) @@ -82,7 +88,10 @@ void should_be_invalid_for_greater_numbers() { void should_be_valid_for_equals_numbers() { assertThat( new MaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(10)), is(true) @@ -93,7 +102,10 @@ void should_be_valid_for_equals_numbers() { void shhould_be_valid_for_smaller_numbers() { assertThat( new MaximumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("maximum", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(Json.createValue(9)), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordTypeTest.java index 190d4311..f9bb600b 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinItemsKeywordTypeTest.java @@ -37,7 +37,10 @@ class MinItemsKeywordTypeTest { @Test void should_be_know_his_name() { final Keyword minItems = new MinItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minItems", Json.createValue(1)).build()) + ); assertThat(minItems.hasName("minItems"), is(true)); assertThat(minItems.hasName("test"), is(false)); @@ -47,7 +50,10 @@ void should_be_know_his_name() { void should_be_valid_for_non_arrays() { assertThat( new MinItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minItems", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -58,7 +64,10 @@ void should_be_valid_for_non_arrays() { void should_be_valid_for_arrays_with_equals_size() { assertThat( new MinItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minItems", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add(1).build()), is(true) @@ -69,7 +78,10 @@ void should_be_valid_for_arrays_with_equals_size() { void should_be_valid_for_arrays_with_greater_size() { assertThat( new MinItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minItems", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add(1).add(2).build()), is(true) @@ -80,7 +92,10 @@ void should_be_valid_for_arrays_with_greater_size() { void should_be_invalid_for_arrays_with_smaller_size() { assertThat( new MinItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minItems", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().build()), is(false) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordTypeTest.java index 1bb69a83..fdb41375 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinLengthKeywordTypeTest.java @@ -29,10 +29,8 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.MinLengthKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; -import jakarta.json.JsonNumber; import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; @@ -40,16 +38,19 @@ class MinLengthKeywordTypeTest { @Test void should_not_be_createbale_with_non_integer() { - final JsonNumber value = Json.createValue(12.3); final MinLengthKeywordType keywordType = new MinLengthKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, value)); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(12.3)).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_know_his_name() { final Keyword keyword = new MinLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(1)).build()) + ); assertThat(keyword.hasName("test"), is(false)); assertThat(keyword.hasName("minLength"), is(true)); @@ -59,7 +60,10 @@ void should_know_his_name() { void should_be_invalid_with_shorter_string() { assertThat( new MinLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("A")), is(false) @@ -70,7 +74,10 @@ void should_be_invalid_with_shorter_string() { void should_be_valid_with_string_with_equal_length() { assertThat( new MinLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("AB")), is(true) @@ -81,7 +88,10 @@ void should_be_valid_with_string_with_equal_length() { void should_be_valid_with_string_that_is_longer() { assertThat( new MinLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue("ABC")), is(true) @@ -92,7 +102,10 @@ void should_be_valid_with_string_that_is_longer() { void should_be_valid_for_non_string_values() { assertThat( new MinLengthKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minLength", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_ARRAY), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordTypeTest.java index c7d35244..66bae1f5 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MinimumKeywordTypeTest.java @@ -27,7 +27,6 @@ import static org.hamcrest.Matchers.is; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.MinimumKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -39,7 +38,10 @@ class MinimumKeywordTypeTest { @Test void should_know_his_name() { final Keyword minimum = new MinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", Json.createValue(1)).build()) + ); assertThat(minimum.hasName("minimum"), is(true)); assertThat(minimum.hasName("test"), is(false)); @@ -48,18 +50,19 @@ void should_know_his_name() { @Test void should_not_becreatable_with_non_number() { final MinimumKeywordType keywordType = new MinimumKeywordType(); - final var schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - Assertions.assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.FALSE) - ); + final var schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", JsonValue.FALSE).build()); + Assertions.assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_non_number_values() { assertThat( new MinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", Json.createValue(1)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -70,7 +73,10 @@ void should_be_valid_for_non_number_values() { void should_be_invalid_for_smaller_numbers() { assertThat( new MinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(-1)), is(false) @@ -81,7 +87,10 @@ void should_be_invalid_for_smaller_numbers() { void should_be_valid_for_equals_numbers() { assertThat( new MinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(0)), is(true) @@ -92,7 +101,10 @@ void should_be_valid_for_equals_numbers() { void shhould_be_valid_for_greater_numbers() { assertThat( new MinimumKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(0)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("minimum", Json.createValue(0)).build()) + ) .asAssertion() .isValidFor(Json.createValue(1)), is(true) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordTypeTest.java index 36a10488..29eb19c2 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/MultipleOfKeywordTypeTest.java @@ -29,7 +29,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.MultipleOfKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -41,7 +40,10 @@ class MultipleOfKeywordTypeTest { @Test void should_know_his_name() { final Keyword multipleOf = new MultipleOfKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("multipleOf", Json.createValue(10)).build()) + ); assertThat(multipleOf.hasName("multipleOf"), is(true)); assertThat(multipleOf.hasName("test"), is(false)); @@ -50,15 +52,19 @@ void should_know_his_name() { @Test void should_not_be_creatable_with_non_integer_value() { final MultipleOfKeywordType keywordType = new MultipleOfKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema, JsonValue.FALSE)); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("multipleOf", JsonValue.FALSE).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_non_number_values() { assertThat( new MultipleOfKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(10)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("multipleOf", Json.createValue(10)).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -69,7 +75,10 @@ void should_be_valid_for_non_number_values() { void should_be_valid_for_a_multipleOf() { assertThat( new MultipleOfKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(1.5)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("multipleOf", Json.createValue(1.5)).build()) + ) .asAssertion() .isValidFor(Json.createValue(4.5)), is(true) @@ -80,7 +89,10 @@ void should_be_valid_for_a_multipleOf() { void should_be_invalid_for_non_multipleOf() { assertThat( new MultipleOfKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue(2)) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("multipleOf", Json.createValue(2)).build()) + ) .asAssertion() .isValidFor(Json.createValue(7)), is(false) @@ -92,8 +104,13 @@ void should_be_valid_for_any_int_if_multipleOf_is_1en8() { assertThat( new MultipleOfKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createValue(new BigDecimal("1e-8")) + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("multipleOf", Json.createValue(new BigDecimal("1e-8"))) + .build() + ) ) .asAssertion() .isValidFor(Json.createValue(12391239123L)), diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordTypeTest.java index 09031c6d..a0e3740c 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/PatternKeywordTypeTest.java @@ -29,7 +29,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.PatternKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -40,17 +39,18 @@ class PatternKeywordTypeTest { @Test void should_be_not_createbale_from_non_string() { final PatternKeywordType keywordType = new PatternKeywordType(); - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); - assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.EMPTY_JSON_OBJECT) - ); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("pattern", JsonValue.EMPTY_JSON_OBJECT).build()); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_know_his_name() { final Keyword pattern = new PatternKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("a")); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("pattern", Json.createValue("a")).build()) + ); assertThat(pattern.hasName("pattern"), is(true)); assertThat(pattern.hasName("test"), is(false)); @@ -60,7 +60,10 @@ void should_be_know_his_name() { void should_be_valid_for_non_string_value() { assertThat( new PatternKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("a")) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("pattern", Json.createValue("a")).build()) + ) .asAssertion() .isValidFor(JsonValue.TRUE), is(true) @@ -72,8 +75,13 @@ void should_be_invalid_for_non_matching_value() { assertThat( new PatternKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$") + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("pattern", Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$")) + .build() + ) ) .asAssertion() .isValidFor(Json.createValue("(888)555-1212 ext. 532")), @@ -86,8 +94,13 @@ void should_be_valid_matching_value() { assertThat( new PatternKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$") + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("pattern", Json.createValue("^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$")) + .build() + ) ) .asAssertion() .isValidFor(Json.createValue("(888)555-1212")), diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordTypeTest.java index eb475225..f91fe85d 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/RequiredKeywordTypeTest.java @@ -38,7 +38,10 @@ class RequiredKeywordTypeTest { @Test void should_know_his_name() { final Keyword required = new RequiredKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.EMPTY_JSON_ARRAY); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("required", JsonValue.EMPTY_JSON_ARRAY).build()) + ); assertThat(required.hasName("required"), is(true)); assertThat(required.hasName("test"), is(false)); @@ -49,8 +52,13 @@ void should_invalid_if_not_all_properties_in_the_instance() { assertThat( new RequiredKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add("foo").add("bar").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("required", Json.createArrayBuilder().add("foo").add("bar")) + .build() + ) ) .asAssertion() .isValidFor(Json.createObjectBuilder().add("foo", BigDecimal.ONE).build()), @@ -63,8 +71,13 @@ void should_valid_for_non_objects() { assertThat( new RequiredKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add("foo").add("bar").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("required", Json.createArrayBuilder().add("foo").add("bar")) + .build() + ) ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_ARRAY), @@ -77,8 +90,13 @@ void should_valid_if_all_properties_are_in_the_instance() { assertThat( new RequiredKeywordType() .createKeyword( - new DefaultJsonSchemaFactory().create(JsonValue.TRUE), - Json.createArrayBuilder().add("foo").add("bar").build() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("required", Json.createArrayBuilder().add("foo").add("bar")) + .build() + ) ) .asAssertion() .isValidFor(Json.createObjectBuilder().add("foo", BigDecimal.ONE).add("bar", "test").build()), diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordTypeTest.java index 5b56cc7a..fdc406aa 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/TypeKeywordTypeTest.java @@ -27,7 +27,6 @@ import static org.hamcrest.Matchers.is; import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; -import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.TypeKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Assertion; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -39,7 +38,10 @@ class TypeKeywordTypeTest { void should_know_his_name() { assertThat( new TypeKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string")) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("type", Json.createValue("string")).build()) + ) .hasName("type"), is(true) ); @@ -49,7 +51,10 @@ void should_know_his_name() { void should_know_other_names() { assertThat( new TypeKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string")) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("type", Json.createValue("string")).build()) + ) .hasName("id"), is(false) ); @@ -58,7 +63,10 @@ void should_know_other_names() { @Test void should_use_stringvalue_to_validate_type() { final Assertion typeAssertion = new TypeKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), Json.createValue("string")) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("type", Json.createValue("string")).build()) + ) .asAssertion(); assertThat(typeAssertion.isValidFor(Json.createValue("value")), is(true)); @@ -71,8 +79,19 @@ 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() + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add( + "type", + 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/validation/UniqueItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordTypeTest.java index 405f2945..746f135d 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/validation/UniqueItemsKeywordTypeTest.java @@ -42,7 +42,10 @@ class UniqueItemsKeywordTypeTest { @Test void should_know_his_name() { final Keyword keyword = new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE); + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.FALSE).build()) + ); assertThat(keyword.hasName("uniqueItems"), is(true)); assertThat(keyword.hasName("test"), is(false)); @@ -50,19 +53,20 @@ void should_know_his_name() { @Test void should_not_be_createbale_from_non_boolean() { - final JsonSchema schema = new DefaultJsonSchemaFactory().create(JsonValue.TRUE); + final JsonSchema schema = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.EMPTY_JSON_OBJECT).build()); final KeywordType keywordType = new UniqueItemsKeywordType(); - assertThrows( - IllegalArgumentException.class, - () -> keywordType.createKeyword(schema, JsonValue.EMPTY_JSON_OBJECT) - ); + assertThrows(IllegalArgumentException.class, () -> keywordType.createKeyword(schema)); } @Test void should_be_valid_for_uniqueItems() { assertThat( new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.TRUE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.TRUE).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add("1").add("2").build()), is(true) @@ -73,7 +77,10 @@ void should_be_valid_for_uniqueItems() { void should_be_valid_for_non_uniqueItems_if_false() { assertThat( new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.FALSE).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add("1").add("1").build()), is(true) @@ -84,7 +91,10 @@ void should_be_valid_for_non_uniqueItems_if_false() { void should_be_invalid_for_non_uniqueItems() { assertThat( new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.TRUE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.TRUE).build()) + ) .asAssertion() .isValidFor(Json.createArrayBuilder().add("1").add("1").build()), is(false) @@ -95,7 +105,10 @@ void should_be_invalid_for_non_uniqueItems() { void should_be_valid_for_non_arrays() { assertThat( new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.FALSE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.FALSE).build()) + ) .asAssertion() .isValidFor(JsonValue.EMPTY_JSON_OBJECT), is(true) @@ -106,7 +119,10 @@ void should_be_valid_for_non_arrays() { void should_be_invalid_if_numbers_mathematically_unequal() { assertThat( new UniqueItemsKeywordType() - .createKeyword(new DefaultJsonSchemaFactory().create(JsonValue.TRUE), JsonValue.TRUE) + .createKeyword( + new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("uniqueItems", JsonValue.TRUE).build()) + ) .asAssertion() .isValidFor(Json.createReader(new StringReader("[1.0,1.00,1]")).readArray()), is(false) 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 b5356049..df0f58ea 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 @@ -31,7 +31,6 @@ import io.github.sebastiantoepfer.jsonschema.JsonSchema; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; -import jakarta.json.JsonValue; import java.net.URI; import org.junit.jupiter.api.Test; @@ -77,7 +76,7 @@ public String name() { } @Override - public Keyword createKeyword(final JsonSchema schema, final JsonValue value) { + public Keyword createKeyword(final JsonSchema schema) { throw new UnsupportedOperationException("Not supported yet."); } } From 165bcf288290c5a626a9dfbd2e33fe8679cbe588 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Sun, 3 Dec 2023 13:33:14 +0100 Subject: [PATCH 4/4] introduce subschema --- .../jsonschema/JsonSchema.java | 2 + .../jsonschema/FakeJsonSchemaFactory.java | 5 ++ .../jsonschema/JsonSubSchemaTest.java | 5 ++ ...hema.java => DefaultJsonObjectSchema.java} | 32 +++++--- .../core/DefaultJsonSchemaFactory.java | 2 +- ...dSearch.java => DefaultJsonSubSchema.java} | 47 ++++++++--- .../jsonschema/core/EmptyJsonSchema.java | 6 ++ .../jsonschema/core/FalseJsonSchema.java | 6 ++ .../jsonschema/core/TrueJsonSchema.java | 6 ++ .../vocab/applicator/ItemsKeywordType.java | 16 ++-- .../core/AbstractJsonValueSchemaTest.java | 6 ++ ....java => DefaultJsonObjectSchemaTest.java} | 58 ++++++++++---- .../core/DefaultJsonSchemaFactoryTest.java | 2 +- .../core/DefaultJsonSubSchemaTest.java | 78 +++++++++++++++++++ .../applicator/ItemsKeywordTypeTest.java | 24 ++++++ 15 files changed, 252 insertions(+), 43 deletions(-) rename core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/{DefaultJsonSchema.java => DefaultJsonObjectSchema.java} (77%) rename core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/{KeywordSearch.java => DefaultJsonSubSchema.java} (55%) rename core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/{DefaultJsonSchemaTest.java => DefaultJsonObjectSchemaTest.java} (66%) create mode 100644 core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchemaTest.java diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java index 2e2da397..2240d3fa 100644 --- a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java +++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/JsonSchema.java @@ -32,6 +32,8 @@ public interface JsonSchema extends JsonValue { Optional keywordByName(String name); + Optional asSubSchema(String name); + default JsonSchema rootSchema() { return this; } diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java index 16ae4822..42f0c41a 100644 --- a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/FakeJsonSchemaFactory.java @@ -51,5 +51,10 @@ public Optional keywordByName(String name) { public JsonValue.ValueType getValueType() { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public Optional asSubSchema(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } } } diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java index f5ac1fa4..f058b4d7 100644 --- a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/JsonSubSchemaTest.java @@ -58,6 +58,11 @@ public Optional keywordByName(String name) { public JsonValue.ValueType getValueType() { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public Optional asSubSchema(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } } .rootSchema(), is(sameInstance(root)) diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchema.java similarity index 77% rename from core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java rename to core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchema.java index 085a8534..cf90c34e 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchema.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchema.java @@ -26,6 +26,8 @@ import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; +import io.github.sebastiantoepfer.jsonschema.InstanceType; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; import io.github.sebastiantoepfer.jsonschema.Validator; import io.github.sebastiantoepfer.jsonschema.core.codition.AllOfCondition; import io.github.sebastiantoepfer.jsonschema.core.codition.ApplicatorBasedCondtion; @@ -33,6 +35,7 @@ import io.github.sebastiantoepfer.jsonschema.core.codition.Condition; import io.github.sebastiantoepfer.jsonschema.core.vocab.core.VocabularyKeywordType; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; +import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType; import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition; import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinitions; import jakarta.json.JsonObject; @@ -41,13 +44,10 @@ import java.util.Optional; import java.util.stream.Stream; -final class DefaultJsonSchema extends AbstractJsonValueSchema { +final class DefaultJsonObjectSchema extends AbstractJsonValueSchema { - private final Keywords keywords; - - public DefaultJsonSchema(final JsonObject value) { + public DefaultJsonObjectSchema(final JsonObject value) { super(value); - keywords = new Keywords(vocabulary()); } @Override @@ -65,9 +65,16 @@ public Optional keywordByName(final String name) { return keywords().filter(k -> k.hasName(name)).findFirst(); } + private Stream keywords() { + final Keywords keywords = new Keywords(vocabulary()); + return asJsonObject().keySet().stream().map(propertyName -> keywords.createKeywordFor(this, propertyName)); + } + private Collection vocabulary() { - return new KeywordSearch(new VocabularyKeywordType()) - .searchForKeywordIn(this) + final KeywordType keywordType = new VocabularyKeywordType(); + return Optional + .ofNullable(asJsonObject().get(keywordType.name())) + .map(keywordValue -> keywordType.createKeyword(this)) .filter(VocabularyDefinitions.class::isInstance) .map(VocabularyDefinitions.class::cast) .stream() @@ -75,8 +82,15 @@ private Collection vocabulary() { .toList(); } - private Stream keywords() { - return asJsonObject().keySet().stream().map(propertyName -> keywords.createKeywordFor(this, propertyName)); + @Override + public Optional asSubSchema(final String name) { + return Optional + .ofNullable(asJsonObject().get(name)) + .filter(value -> + Stream.of(InstanceType.BOOLEAN, InstanceType.OBJECT).anyMatch(type -> type.isInstance(value)) + ) + .map(new DefaultJsonSchemaFactory()::create) + .map(subSchema -> new DefaultJsonSubSchema(this, subSchema)); } private Optional> asContraint(final Keyword keyword) { diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactory.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactory.java index 49bf94c9..2435ac13 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactory.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactory.java @@ -39,7 +39,7 @@ public JsonSchema create(final JsonValue schema) { } else if (schema.equals(JsonValue.EMPTY_JSON_OBJECT)) { result = new EmptyJsonSchema(); } else { - result = new DefaultJsonSchema(schema.asJsonObject()); + result = new DefaultJsonObjectSchema(schema.asJsonObject()); } return result; } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchema.java similarity index 55% rename from core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java rename to core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchema.java index 5f597514..dd3d8787 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/KeywordSearch.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchema.java @@ -24,23 +24,50 @@ package io.github.sebastiantoepfer.jsonschema.core; import io.github.sebastiantoepfer.jsonschema.JsonSchema; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; +import io.github.sebastiantoepfer.jsonschema.Validator; 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; -@Deprecated -final class KeywordSearch { +final class DefaultJsonSubSchema implements JsonSubSchema { - private final KeywordType keywordType; + private final JsonSchema owner; + private final JsonSchema schema; - public KeywordSearch(final KeywordType keywordType) { - this.keywordType = Objects.requireNonNull(keywordType); + public DefaultJsonSubSchema(final JsonSchema owner, final JsonSchema schema) { + this.owner = Objects.requireNonNull(owner); + this.schema = Objects.requireNonNull(schema); } - public Optional searchForKeywordIn(final JsonSchema schema) { - return Optional - .ofNullable(schema.asJsonObject().get(keywordType.name())) - .map(keywordValue -> keywordType.createKeyword(schema)); + @Override + public JsonSchema owner() { + return owner; + } + + @Override + public Validator validator() { + return schema.validator(); + } + + @Override + public Optional keywordByName(final String name) { + return schema.keywordByName(name); + } + + @Override + public Optional asSubSchema(final String name) { + return schema.asSubSchema(name); + } + + @Override + public ValueType getValueType() { + return schema.getValueType(); + } + + @Override + public JsonObject asJsonObject() { + return schema.asJsonObject(); } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/EmptyJsonSchema.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/EmptyJsonSchema.java index 1282dd9e..47242c62 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/EmptyJsonSchema.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/EmptyJsonSchema.java @@ -23,6 +23,7 @@ */ package io.github.sebastiantoepfer.jsonschema.core; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; import io.github.sebastiantoepfer.jsonschema.Validator; import io.github.sebastiantoepfer.jsonschema.core.codition.NoCondition; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; @@ -44,4 +45,9 @@ public Validator validator() { public Optional keywordByName(final String name) { return Optional.empty(); } + + @Override + public Optional asSubSchema(final String name) { + return Optional.empty(); + } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/FalseJsonSchema.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/FalseJsonSchema.java index 942b6e9d..26086cb2 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/FalseJsonSchema.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/FalseJsonSchema.java @@ -23,6 +23,7 @@ */ package io.github.sebastiantoepfer.jsonschema.core; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; import io.github.sebastiantoepfer.jsonschema.Validator; import io.github.sebastiantoepfer.jsonschema.core.codition.UnfulfillableCondition; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; @@ -44,4 +45,9 @@ public Validator validator() { public Optional keywordByName(final String name) { return Optional.empty(); } + + @Override + public Optional asSubSchema(final String name) { + return Optional.empty(); + } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/TrueJsonSchema.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/TrueJsonSchema.java index 598e17d1..dec65232 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/TrueJsonSchema.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/TrueJsonSchema.java @@ -23,6 +23,7 @@ */ package io.github.sebastiantoepfer.jsonschema.core; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; import io.github.sebastiantoepfer.jsonschema.Validator; import io.github.sebastiantoepfer.jsonschema.core.codition.NoCondition; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; @@ -44,4 +45,9 @@ public Validator validator() { public Optional keywordByName(final String name) { return Optional.empty(); } + + @Override + public Optional asSubSchema(final String name) { + return Optional.empty(); + } } diff --git a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java index 2a238f55..7fbebacd 100644 --- a/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java +++ b/core/src/main/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordType.java @@ -25,7 +25,6 @@ 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.keyword.Annotation; @@ -49,22 +48,20 @@ public String name() { @Override public Keyword createKeyword(final JsonSchema schema) { - return new ItemsKeyword(schema, JsonSchemas.load(schema.asJsonObject().get(name()))); + return schema.asSubSchema(name()).map(ItemsKeyword::new).orElseThrow(IllegalArgumentException::new); } private class ItemsKeyword implements Applicator, Annotation, JsonSubSchema { - private final JsonSchema owner; - private final JsonSchema schema; + private final JsonSubSchema schema; - public ItemsKeyword(final JsonSchema owner, final JsonSchema schema) { - this.owner = Objects.requireNonNull(owner); + public ItemsKeyword(final JsonSubSchema schema) { this.schema = Objects.requireNonNull(schema); } @Override public JsonSchema owner() { - return owner; + return schema.owner(); } @Override @@ -82,6 +79,11 @@ public Optional keywordByName(final String name) { return schema.keywordByName(name); } + @Override + public Optional asSubSchema(final String name) { + return schema.asSubSchema(name); + } + @Override public boolean hasName(final String name) { return Objects.equals(name(), name); diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/AbstractJsonValueSchemaTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/AbstractJsonValueSchemaTest.java index e8744b8c..83eb06fb 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/AbstractJsonValueSchemaTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/AbstractJsonValueSchemaTest.java @@ -27,6 +27,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; +import io.github.sebastiantoepfer.jsonschema.JsonSubSchema; import io.github.sebastiantoepfer.jsonschema.Validator; import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; import jakarta.json.JsonArray; @@ -72,5 +73,10 @@ public Validator validator() { public Optional keywordByName(final String name) { return Optional.empty(); } + + @Override + public Optional asSubSchema(final String name) { + return Optional.empty(); + } } } diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchemaTest.java similarity index 66% rename from core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaTest.java rename to core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchemaTest.java index dd07c2ab..274099f2 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonObjectSchemaTest.java @@ -28,16 +28,15 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertThrows; import jakarta.json.Json; -import jakarta.json.JsonObject; import jakarta.json.JsonValue; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -class DefaultJsonSchemaTest { +class DefaultJsonObjectSchemaTest { - private final DefaultJsonSchema schema = new DefaultJsonSchema( + private final DefaultJsonObjectSchema schema = new DefaultJsonObjectSchema( Json .createObjectBuilder() .add("type", "array") @@ -66,22 +65,24 @@ void should_be_invalid_for_object() { } @Test - void should_not_be_loadable_without_mandantory_core_vocabulary() { - final JsonObject invalidSchema = Json - .createObjectBuilder() - .add( - "$vocabulary", - Json.createObjectBuilder().add("https://json-schema.org/draft/2020-12/vocab/core", false) - ) - .build(); + void should_not_be_usable_without_mandantory_core_vocabulary() { + final DefaultJsonObjectSchema invalidSchema = new DefaultJsonObjectSchema( + Json + .createObjectBuilder() + .add( + "$vocabulary", + Json.createObjectBuilder().add("https://json-schema.org/draft/2020-12/vocab/core", false) + ) + .build() + ); - Assertions.assertThrows(Exception.class, () -> new DefaultJsonSchema(invalidSchema)); + assertThrows(IllegalArgumentException.class, () -> invalidSchema.keywordByName("$vocabulary")); } @Test void should_find_keyword_by_name() { assertThat( - new DefaultJsonSchema( + new DefaultJsonObjectSchema( Json .createObjectBuilder() .add( @@ -98,7 +99,7 @@ void should_find_keyword_by_name() { @Test void should_return_empty_for_non_existing_keyword() { assertThat( - new DefaultJsonSchema( + new DefaultJsonObjectSchema( Json .createObjectBuilder() .add( @@ -111,4 +112,31 @@ void should_return_empty_for_non_existing_keyword() { isEmpty() ); } + + @Test + void should_return_empty_if_non_subschema_exists_under_the_given_name() { + assertThat( + new DefaultJsonObjectSchema(Json.createObjectBuilder().add("test", "hallo").build()) + .asSubSchema("properties"), + isEmpty() + ); + } + + @Test + void should_return_subschema_if_subschema_exists_under_the_given_name() { + assertThat( + new DefaultJsonObjectSchema(Json.createObjectBuilder().add("test", JsonValue.FALSE).build()) + .asSubSchema("test"), + isPresent() + ); + } + + @Test + void should_return_empty_if_given_name_not_resolve_to_a_valid_schematype() { + assertThat( + new DefaultJsonObjectSchema(Json.createObjectBuilder().add("test", JsonValue.EMPTY_JSON_ARRAY).build()) + .asSubSchema("test"), + isEmpty() + ); + } } diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactoryTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactoryTest.java index bab69f66..075242f5 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactoryTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSchemaFactoryTest.java @@ -55,7 +55,7 @@ void should_return_emptyjsonschema_for_emptyobject() { void should_return_defaultjsonschema_for_everything_else() { assertThat( new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("type", "string").build()), - is(instanceOf(DefaultJsonSchema.class)) + is(instanceOf(DefaultJsonObjectSchema.class)) ); } } diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchemaTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchemaTest.java new file mode 100644 index 00000000..45851da4 --- /dev/null +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/DefaultJsonSubSchemaTest.java @@ -0,0 +1,78 @@ +/* + * 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; + +import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import io.github.sebastiantoepfer.jsonschema.JsonSchema; +import jakarta.json.Json; +import jakarta.json.JsonValue; +import org.junit.jupiter.api.Test; + +class DefaultJsonSubSchemaTest { + + @Test + void should_return_owner() { + final JsonSchema owner = new DefaultJsonSchemaFactory() + .create(Json.createObjectBuilder().add("test", JsonValue.TRUE).build()); + assertThat( + new DefaultJsonSubSchema(owner, new DefaultJsonSchemaFactory().create(JsonValue.TRUE)).owner(), + is(owner) + ); + } + + @Test + void should_return_subschema() { + final JsonSchema owner = new DefaultJsonSchemaFactory() + .create( + Json.createObjectBuilder().add("test", Json.createObjectBuilder().add("sub", JsonValue.TRUE)).build() + ); + assertThat( + new DefaultJsonSubSchema( + owner, + new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("sub", JsonValue.TRUE).build()) + ) + .asSubSchema("sub"), + isPresent() + ); + } + + @Test + void should_convertable_to_plain_jsonobject() { + final JsonSchema owner = new DefaultJsonSchemaFactory() + .create( + Json.createObjectBuilder().add("test", Json.createObjectBuilder().add("sub", JsonValue.TRUE)).build() + ); + assertThat( + new DefaultJsonSubSchema( + owner, + new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("sub", JsonValue.TRUE).build()) + ) + .asJsonObject(), + is(Json.createObjectBuilder().add("sub", JsonValue.TRUE).build()) + ); + } +} diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java index 8814f8f3..5f7f1789 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/vocab/applicator/ItemsKeywordTypeTest.java @@ -229,4 +229,28 @@ void should_be_invalid_if_invaliditem_is_not_already_checked_by_prefixItems() { is(false) ); } + + @Test + void should_be_return_subSchemas() { + assertThat( + ((JsonSubSchema) new ItemsKeywordType() + .createKeyword( + new DefaultJsonSchemaFactory() + .create( + Json + .createObjectBuilder() + .add("prefixItems", Json.createArrayBuilder().add(true)) + .add( + "items", + Json + .createObjectBuilder() + .add("type", "object") + .add("properties", Json.createObjectBuilder().add("test", JsonValue.TRUE)) + ) + .build() + ) + )).asSubSchema("properties"), + isPresent() + ); + } }