Skip to content

Commit

Permalink
Merge pull request #7 from sebastian-toepfer/core-vocabulary
Browse files Browse the repository at this point in the history
add the core vocabulary
  • Loading branch information
sebastian-toepfer authored Sep 10, 2023
2 parents 8c7de2c + 50c1a6b commit eed14f6
Show file tree
Hide file tree
Showing 94 changed files with 2,572 additions and 285 deletions.
49 changes: 49 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.sebastian-toepfer.json-schema</groupId>
<artifactId>json-schema</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>json-schema-api</artifactId>
<name>Json Schema :: api</name>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

public final class ConstraintViolation {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

import jakarta.json.JsonNumber;
import jakarta.json.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

import jakarta.json.JsonValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

import io.github.sebastiantoepfer.jsonschema.core.spi.JsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory;
import jakarta.json.Json;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

import jakarta.json.Json;
import jakarta.json.JsonReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core;
package io.github.sebastiantoepfer.jsonschema;

import io.github.sebastiantoepfer.jsonschema.core.keyword.KeywordType;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
import java.net.URI;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import jakarta.json.JsonValue;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import jakarta.json.JsonValue;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import jakarta.json.JsonValue;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import jakarta.json.JsonValue;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import java.net.URI;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import jakarta.json.JsonValue;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import java.util.Collection;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.spi;
package io.github.sebastiantoepfer.jsonschema.spi;

import io.github.sebastiantoepfer.jsonschema.core.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import jakarta.json.JsonValue;

public interface JsonSchemaFactory {
Expand Down
31 changes: 31 additions & 0 deletions api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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.
*/

module io.github.sebastiantoepfer.jsonschema {
exports io.github.sebastiantoepfer.jsonschema;
exports io.github.sebastiantoepfer.jsonschema.keyword;
exports io.github.sebastiantoepfer.jsonschema.spi;

requires jakarta.json;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory;
import jakarta.json.JsonValue;

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.");
}

@Override
public JsonValue.ValueType getValueType() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 jakarta.json.Json;
import jakarta.json.JsonValue;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class InstanceTypeTest {

@ParameterizedTest
@MethodSource("provideWithValidCombinations")
void should_be_true_if_instancetype_is_correct(final InstanceType instanceType, final JsonValue value) {
assertThat(instanceType.isInstance(value), is(true));
}

static Stream<? extends Arguments> provideWithValidCombinations() {
return Stream.of(
Arguments.of(InstanceType.NULL, JsonValue.NULL),
Arguments.of(InstanceType.BOOLEAN, JsonValue.FALSE),
Arguments.of(InstanceType.BOOLEAN, JsonValue.TRUE),
Arguments.of(InstanceType.OBJECT, JsonValue.EMPTY_JSON_OBJECT),
Arguments.of(InstanceType.ARRAY, JsonValue.EMPTY_JSON_ARRAY),
Arguments.of(InstanceType.NUMBER, Json.createValue(23L)),
Arguments.of(InstanceType.INTEGER, Json.createValue(23L)),
Arguments.of(InstanceType.INTEGER, Json.createValue(0.0))
);
}

@ParameterizedTest
@MethodSource("provideWithInvalidCombinations")
void should_be_false_if_instancetype_is_correct(final InstanceType instanceType, final JsonValue value) {
assertThat(instanceType.isInstance(value), is(false));
}

static Stream<? extends Arguments> provideWithInvalidCombinations() {
return Stream.of(
Arguments.of(InstanceType.NULL, JsonValue.TRUE),
Arguments.of(InstanceType.BOOLEAN, JsonValue.EMPTY_JSON_OBJECT),
Arguments.of(InstanceType.BOOLEAN, JsonValue.EMPTY_JSON_ARRAY),
Arguments.of(InstanceType.OBJECT, JsonValue.EMPTY_JSON_ARRAY),
Arguments.of(InstanceType.ARRAY, JsonValue.TRUE),
Arguments.of(InstanceType.NUMBER, Json.createValue("string")),
Arguments.of(InstanceType.INTEGER, Json.createValue(23.2)),
Arguments.of(InstanceType.INTEGER, Json.createValue("test"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.impl.keyword;
package io.github.sebastiantoepfer.jsonschema;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

import jakarta.json.Json;
import org.junit.jupiter.api.Test;

class TypeTest {
class JsonSchemasTest {

@Test
void should_know_his_name() {
assertThat(new Type(Json.createValue("string")).hasName("type"), is(true));
}

@Test
void should_know_other_names() {
assertThat(new Type(Json.createValue("string")).hasName("id"), is(false));
void should_return_a_schema() {
assertThat(JsonSchemas.load("{}"), is(not(nullValue())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword;
package io.github.sebastiantoepfer.jsonschema.keyword;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down
Loading

0 comments on commit eed14f6

Please sign in to comment.