Skip to content

Commit

Permalink
Merge branch 'main' into fix_refkeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-toepfer committed Jun 12, 2024
2 parents dcb74bb + 9114ca6 commit 653df21
Show file tree
Hide file tree
Showing 95 changed files with 3,043 additions and 1,443 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sebastian-toepfer_json-schema&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sebastian-toepfer_json-schema)
[![Reproducible Builds](https://img.shields.io/badge/Reproducible_Builds-ok-success?labelColor=1e5b96)](https://github.com/jvm-repo-rebuild/reproducible-central#io.github.sebastian-toepfer.json-schema:json-schema)
![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/sebastian-toepfer_json-schema?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Tests](https://img.shields.io/sonar/tests/sebastian-toepfer_json-schema?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations](https://img.shields.io/sonar/violations/sebastian-toepfer_json-schema?server=https%3A%2F%2Fsonarcloud.io)

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/sebastian-toepfer/json-schema/build.yml)

![Maven Central Version](https://img.shields.io/maven-central/v/io.github.sebastian-toepfer.json-schema/json-schema)
![GitHub Release](https://img.shields.io/github/v/release/sebastian-toepfer/json-schema)
![GitHub commits since latest release](https://img.shields.io/github/commits-since/sebastian-toepfer/json-schema/latest)

[![Reproducible Builds](https://img.shields.io/badge/Reproducible_Builds-ok-success?labelColor=1e5b96)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/io/github/sebastian-toepfer/json-schema/json-schema/README.md)

# json-schema
json schema for json-api
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.sebastian-toepfer.json-schema</groupId>
<artifactId>json-schema</artifactId>
<version>0.2.1</version>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>json-schema-api</artifactId>
Expand Down
29 changes: 20 additions & 9 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.sebastian-toepfer.json-schema</groupId>
<artifactId>json-schema</artifactId>
<version>0.2.1</version>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>json-schema-core</artifactId>
Expand Down Expand Up @@ -81,14 +81,7 @@
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<scope>test</scope>
</dependency>

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

</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
Expand All @@ -99,6 +92,17 @@
<artifactId>media-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>

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

<dependency>
<groupId>com.github.spotbugs</groupId>
Expand All @@ -117,10 +121,14 @@
<include>**/tests/draft2019-09/additionalItems.json</include>
-->
<include>**/tests/draft2020-12/additionalProperties.json</include>
<include>**/tests/draft2020-12/allOf.json</include>
<include>**/tests/draft2020-12/anyOf.json</include>
<include>**/tests/draft2020-12/oneOf.json</include>
<include>**/tests/draft2020-12/boolean_schema.json</include>
<include>**/tests/draft2020-12/const.json</include>
<include>**/tests/draft2020-12/contains.json</include>
<include>**/tests/draft2020-12/dependentRequired.json</include>
<include>**/tests/draft2020-12/dependentSchemas.json</include>
<include>**/tests/draft2020-12/enum.json</include>
<include>**/tests/draft2020-12/exclusiveMaximum.json</include>
<include>**/tests/draft2020-12/exclusiveMinimum.json</include>
Expand All @@ -139,6 +147,9 @@
<include>**/tests/draft2020-12/minLength.json</include>
<include>**/tests/draft2020-12/minimum.json</include>
<include>**/tests/draft2020-12/minProperties.json</include>
<!-- more than not -> unevaluatedProperties :(
<include>**/tests/draft2020-12/not.json</include>
-->
<include>**/tests/draft2020-12/multipleOf.json</include>
<include>**/tests/draft2020-12/pattern.json</include>
<include>**/tests/draft2020-12/patternProperties.json</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public final JsonObject asJsonObject() {
public final JsonArray asJsonArray() {
return value.asJsonArray();
}

@Override
public String toString() {
return value.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ public ValueType getValueType() {
public JsonObject asJsonObject() {
return schema.asJsonObject();
}

@Override
public String toString() {
return schema.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.Vocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.applicator.ApplicatorVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.content.ContentVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.core.CoreVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.format.FormatAnnotationVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.meta.MetaDataVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.unevaluated.UnevaluatedVocabulary;
import io.github.sebastiantoepfer.jsonschema.core.vocab.validation.ValidationVocabulary;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.vocabulary.spi.VocabularyDefinition;
Expand All @@ -54,7 +58,14 @@ final class Keywords {
.stream()
.collect(toMap(Vocabulary::id, Function.identity()));

DEFAULT_VOCABS = List.of(new ValidationVocabulary(JsonProvider.provider()), new ApplicatorVocabulary());
DEFAULT_VOCABS = List.of(
new ApplicatorVocabulary(),
new ValidationVocabulary(JsonProvider.provider()),
new MetaDataVocabulary(),
new FormatAnnotationVocabulary(),
new UnevaluatedVocabulary(),
new ContentVocabulary()
);
}

private final Collection<Vocabulary> vocabularies;
Expand All @@ -63,8 +74,8 @@ public Keywords(final Collection<VocabularyDefinition> vocabDefs) {
if (
vocabDefs
.stream()
.filter(vocabDef -> MANDANTORY_VOCABS.containsKey(vocabDef.id()))
.anyMatch(not(VocabularyDefinition::required))
.filter(vocabDef -> MANDANTORY_VOCABS.keySet().stream().anyMatch(vocabDef::hasid))
.anyMatch(not(VocabularyDefinition::isRequired))
) {
throw new IllegalArgumentException("can not be created without core vocabulary is requiered!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright 2024 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.keyword.type;

import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;

public enum AffectByType {
EXTENDS {
@Override
Keyword affect(final Keyword affectedKeyword) {
return affectedKeyword;
}
},
REPLACE {
@Override
Keyword affect(final Keyword affectedKeyword) {
return new ReplacingKeyword(affectedKeyword);
}
};

abstract Keyword affect(final Keyword affectedKeyword);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* The MIT License
*
* Copyright 2024 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.keyword.type;

import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;

public final class AffectedBy implements Comparable<AffectedBy> {

private final AffectByType type;
private final String name;

public AffectedBy(final AffectByType type, final String name) {
this.type = Objects.requireNonNull(type);
this.name = Objects.requireNonNull(name);
}

@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.type);
hash = 83 * hash + Objects.hashCode(this.name);
return hash;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
return compareTo((AffectedBy) obj) == 0;
}

@Override
public int compareTo(final AffectedBy other) {
final int result;
if (type.compareTo(other.type) == 0) {
result = name.compareTo(other.name);
} else {
result = type.compareTo(other.type);
}
return result;
}

Function<Keyword, Keyword> findAffectedByKeywordIn(final JsonSchema schema) {
final UnaryOperator<Keyword> result;
if (schema.keywordByName(name).isPresent()) {
result = type::affect;
} else {
result = k -> k;
}
return result;
}

@Override
public String toString() {
return "AffectedBy{" + "type=" + type + ", name=" + name + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@
*/
package io.github.sebastiantoepfer.jsonschema.core.keyword.type;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Function;

public class AffectedByKeywordType implements KeywordType {
public final class AffectedByKeywordType implements KeywordType {

private final String name;
private final List<String> affectedBy;
private final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator;
private final Collection<AffectedBy> affectedBy;
private final Function<JsonSchema, Keyword> keywordCreator;

public AffectedByKeywordType(
final String name,
final List<String> affectedBy,
final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator
final Collection<AffectedBy> affectedBy,
final Function<JsonSchema, Keyword> keywordCreator
) {
if (affectedBy.isEmpty()) {
throw new IllegalArgumentException("affectedBy can not be empty!");
}
this.name = Objects.requireNonNull(name);
this.affectedBy = List.copyOf(affectedBy);
this.keywordCreator = Objects.requireNonNull(keywordCreator);
Expand All @@ -57,34 +59,35 @@ public String name() {

@Override
public Keyword createKeyword(final JsonSchema schema) {
return new AffectedByKeyword(schema, name, affectedBy, keywordCreator);
return new AffectedKeyword(schema, name, affectedBy, keywordCreator);
}

static final class AffectedByKeyword extends KeywordRelationship {
static final class AffectedKeyword extends KeywordRelationship {

private final JsonSchema schema;
private final List<String> affectedBy;
private final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator;
private final SortedSet<AffectedBy> affectedBy;
private final Function<JsonSchema, Keyword> keywordCreator;

public AffectedByKeyword(
public AffectedKeyword(
final JsonSchema schema,
final String name,
final List<String> affectedBy,
final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator
final Collection<AffectedBy> affectedBy,
final Function<JsonSchema, Keyword> keywordCreator
) {
super(name);
this.schema = Objects.requireNonNull(schema);
this.affectedBy = List.copyOf(affectedBy);
this.affectedBy = new TreeSet<>(affectedBy);
this.keywordCreator = Objects.requireNonNull(keywordCreator);
}

@Override
protected Keyword delegate() {
return affectedBy
.stream()
.map(schema::keywordByName)
.flatMap(Optional::stream)
.collect(collectingAndThen(toList(), k -> keywordCreator.apply(k, schema)));
.map(a -> a.findAffectedByKeywordIn(schema))
.reduce(Function::andThen)
.orElseThrow()
.apply(keywordCreator.apply(schema));
}
}
}
Loading

0 comments on commit 653df21

Please sign in to comment.