-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from sebastian-toepfer/keyword_minContains
add support for minContains keyword
- Loading branch information
Showing
13 changed files
with
746 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...n/java/io/github/sebastiantoepfer/jsonschema/core/keyword/type/AffectedByKeywordType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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 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.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
||
public class AffectedByKeywordType implements KeywordType { | ||
|
||
private final String name; | ||
private final List<String> affectedBy; | ||
private final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator; | ||
|
||
public AffectedByKeywordType( | ||
final String name, | ||
final List<String> affectedBy, | ||
final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator | ||
) { | ||
this.name = Objects.requireNonNull(name); | ||
this.affectedBy = List.copyOf(affectedBy); | ||
this.keywordCreator = Objects.requireNonNull(keywordCreator); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Keyword createKeyword(final JsonSchema schema) { | ||
return new AffectedByKeyword(schema, name, affectedBy, keywordCreator); | ||
} | ||
|
||
static final class AffectedByKeyword extends KeywordRelationship { | ||
|
||
private final JsonSchema schema; | ||
private final List<String> affectedBy; | ||
private final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator; | ||
|
||
public AffectedByKeyword( | ||
final JsonSchema schema, | ||
final String name, | ||
final List<String> affectedBy, | ||
final BiFunction<List<Keyword>, JsonSchema, Keyword> keywordCreator | ||
) { | ||
super(name); | ||
this.schema = Objects.requireNonNull(schema); | ||
this.affectedBy = List.copyOf(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))); | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...main/java/io/github/sebastiantoepfer/jsonschema/core/keyword/type/AffectsKeywordType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.Annotation; | ||
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; | ||
import java.util.function.BiFunction; | ||
|
||
public class AffectsKeywordType implements KeywordType { | ||
|
||
private final String name; | ||
private final String affects; | ||
private final BiFunction<Annotation, JsonSchema, Keyword> keywordCreator; | ||
|
||
public AffectsKeywordType( | ||
final String name, | ||
final String affects, | ||
final BiFunction<Annotation, JsonSchema, Keyword> keywordCreator | ||
) { | ||
this.name = name; | ||
this.affects = affects; | ||
this.keywordCreator = keywordCreator; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Keyword createKeyword(final JsonSchema schema) { | ||
return new AffectsKeyword(schema, name, affects, keywordCreator); | ||
} | ||
|
||
static final class AffectsKeyword extends KeywordRelationship { | ||
|
||
private final JsonSchema schema; | ||
private final String affects; | ||
private final BiFunction<Annotation, JsonSchema, Keyword> keywordCreator; | ||
|
||
public AffectsKeyword( | ||
final JsonSchema schema, | ||
final String name, | ||
final String affects, | ||
final BiFunction<Annotation, JsonSchema, Keyword> keywordCreator | ||
) { | ||
super(name); | ||
this.schema = Objects.requireNonNull(schema); | ||
this.affects = affects; | ||
this.keywordCreator = Objects.requireNonNull(keywordCreator); | ||
} | ||
|
||
@Override | ||
protected Keyword delegate() { | ||
return keywordCreator.apply( | ||
schema | ||
.keywordByName(affects) | ||
.map(Keyword::asAnnotation) | ||
.orElseGet(() -> new StaticAnnotation(affects, JsonValue.NULL)), | ||
schema | ||
); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...ain/java/io/github/sebastiantoepfer/jsonschema/core/keyword/type/KeywordRelationship.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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.ddd.common.Media; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.Annotation; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.Applicator; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.Assertion; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.Identifier; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword; | ||
import io.github.sebastiantoepfer.jsonschema.keyword.ReservedLocation; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
abstract class KeywordRelationship implements Keyword { | ||
|
||
private final String name; | ||
|
||
protected KeywordRelationship(final String name) { | ||
this.name = Objects.requireNonNull(name); | ||
} | ||
|
||
@Override | ||
public final Collection<Keyword.KeywordCategory> categories() { | ||
return delegate().categories(); | ||
} | ||
|
||
@Override | ||
public final boolean hasName(final String name) { | ||
return Objects.equals(this.name, name); | ||
} | ||
|
||
@Override | ||
public final <T extends Media<T>> T printOn(final T media) { | ||
return delegate().printOn(media); | ||
} | ||
|
||
@Override | ||
public final Identifier asIdentifier() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public final Assertion asAssertion() { | ||
return delegate().asAssertion(); | ||
} | ||
|
||
@Override | ||
public final Annotation asAnnotation() { | ||
return delegate().asAnnotation(); | ||
} | ||
|
||
@Override | ||
public final Applicator asApplicator() { | ||
return delegate().asApplicator(); | ||
} | ||
|
||
@Override | ||
public final ReservedLocation asReservedLocation() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
protected abstract Keyword delegate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.