Skip to content

Commit

Permalink
Merge pull request #97 from sebastian-toepfer/smaller_refactoring
Browse files Browse the repository at this point in the history
smaller refactoring
  • Loading branch information
sebastian-toepfer authored Jan 18, 2024
2 parents 0a6bc3a + 59c0852 commit f623435
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.codition;

import java.util.Objects;
import java.util.function.Function;

public final class MappingConditionAdapter<T, R> implements Condition<T> {

private final Function<T, Boolean> check;

public MappingConditionAdapter(final Condition<R> condition, final Function<T, R> map) {
this.check = Objects.requireNonNull(map).andThen(condition::isFulfilledBy);
}

@Override
public boolean isFulfilledBy(final T value) {
return check.apply(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.github.sebastiantoepfer.jsonschema.core.codition.AllOfCondition;
import io.github.sebastiantoepfer.jsonschema.core.codition.CollectionElementsCondtion;
import io.github.sebastiantoepfer.jsonschema.core.codition.JsonPropertyCondition;
import io.github.sebastiantoepfer.jsonschema.core.codition.MappingConditionAdapter;
import io.github.sebastiantoepfer.jsonschema.core.codition.OfTypeCondition;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import io.github.sebastiantoepfer.jsonschema.keyword.KeywordType;
Expand Down Expand Up @@ -74,9 +75,10 @@ private Keyword createKeyword(final JsonObject schema) {
jsonContext.createPointer(String.format("/%s", name)),
new AllOfCondition<>(
new OfTypeCondition(InstanceType.ARRAY),
json ->
new CollectionElementsCondtion<JsonValue>(new OfTypeCondition(InstanceType.STRING))
.isFulfilledBy(json.asJsonArray())
new MappingConditionAdapter<>(
new CollectionElementsCondtion<>(new OfTypeCondition(InstanceType.STRING)),
JsonValue::asJsonArray
)
)
)
.isFulfilledBy(schema)
Expand Down

0 comments on commit f623435

Please sign in to comment.