Skip to content

Commit

Permalink
Bump io.github.sebastian-toepfer.oss:oss-parent from 0.4.0 to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-toepfer authored Feb 27, 2024
2 parents 762b5ba + 6bd3592 commit a76678a
Show file tree
Hide file tree
Showing 61 changed files with 388 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

public final class JsonSchemas {

private static final JsonSchemaFactory JSONSCHEMA_FACTORY = ServiceLoader
.load(JsonSchemaFactory.class)
private static final JsonSchemaFactory JSONSCHEMA_FACTORY = ServiceLoader.load(JsonSchemaFactory.class)
.findFirst()
.orElseThrow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ private Stream<Keyword> keywords() {

@Override
public Optional<JsonSubSchema> asSubSchema(final String name) {
return Optional
.ofNullable(asJsonObject().get(name))
return Optional.ofNullable(asJsonObject().get(name))
.flatMap(new DefaultJsonSchemaFactory()::tryToCreateSchemaFrom)
.map(subSchema -> new DefaultJsonSubSchema(this, subSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ private Stream<Keyword> keywords() {
final Stream<Keyword> result;
if (isJsonObject()) {
final Keywords keywords = new KeywordExtractor(schema).createKeywords();
result =
asJsonObject().keySet().stream().map(propertyName -> keywords.createKeywordFor(this, propertyName));
result = asJsonObject()
.keySet()
.stream()
.map(propertyName -> keywords.createKeywordFor(this, propertyName));
} else {
result = Stream.empty();
}
Expand All @@ -91,8 +93,7 @@ private boolean isJsonObject() {

@Override
public Optional<JsonSubSchema> asSubSchema(final String name) {
return Optional
.ofNullable(asJsonObject().get(name))
return Optional.ofNullable(asJsonObject().get(name))
.flatMap(new DefaultJsonSchemaFactory()::tryToCreateSchemaFrom)
.map(subSchema -> new DefaultJsonSubSchema(this, subSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ final class KeywordBasedValidator implements Validator {
private final DefaultValidator validator;

public KeywordBasedValidator(final Collection<Keyword> keywords) {
this.validator =
keywords
.stream()
.map(KeywordBasedValidator::asContraint)
.flatMap(Optional::stream)
.collect(collectingAndThen(toList(), constraints -> new DefaultValidator(new AllOf<>(constraints))));
this.validator = keywords
.stream()
.map(KeywordBasedValidator::asContraint)
.flatMap(Optional::stream)
.collect(collectingAndThen(toList(), constraints -> new DefaultValidator(new AllOf<>(constraints))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ public Keywords createKeywords() {
if (
schema.getValueType() == JsonValue.ValueType.OBJECT && schema.asJsonObject().containsKey(keywordType.name())
) {
result =
keywordType
.createKeyword(schema)
.definitions()
.collect(Collectors.collectingAndThen(Collectors.toList(), Keywords::new));
result = keywordType
.createKeyword(schema)
.definitions()
.collect(Collectors.collectingAndThen(Collectors.toList(), Keywords::new));
} else {
result = new Keywords(List.of());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ final class Keywords {
private static final Collection<Vocabulary> DEFAULT_VOCABS;

static {
MANDANTORY_VOCABS =
List
.of(new BasicVocabulary(), new CoreVocabulary(JsonProvider.provider()))
.stream()
.collect(toMap(Vocabulary::id, Function.identity()));
MANDANTORY_VOCABS = List.of(new BasicVocabulary(), new CoreVocabulary(JsonProvider.provider()))
.stream()
.collect(toMap(Vocabulary::id, Function.identity()));

DEFAULT_VOCABS = List.of(new ValidationVocabulary(JsonProvider.provider()), new ApplicatorVocabulary());
}
Expand All @@ -70,19 +68,16 @@ public Keywords(final Collection<VocabularyDefinition> vocabDefs) {
) {
throw new IllegalArgumentException("can not be created without core vocabulary is requiered!");
}
vocabularies =
Stream
.concat(
Stream.concat(MANDANTORY_VOCABS.values().stream(), DEFAULT_VOCABS.stream()),
vocabDefs.stream().map(VocabularyDefinition::findVocabulary).flatMap(Optional::stream)
)
.collect(
Collector.of(
ArrayDeque::new,
ArrayDeque::addFirst,
(first, last) -> null //pitest otherwise see mutants here :(
)
);
vocabularies = Stream.concat(
Stream.concat(MANDANTORY_VOCABS.values().stream(), DEFAULT_VOCABS.stream()),
vocabDefs.stream().map(VocabularyDefinition::findVocabulary).flatMap(Optional::stream)
).collect(
Collector.of(
ArrayDeque::new,
ArrayDeque::addFirst,
(first, last) -> null //pitest otherwise see mutants here :(
)
);
}

public Keyword createKeywordFor(final JsonSchema schema, final String propertyName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ private Keyword createKeyword(final JsonObject schema) {
new JsonPropertyWhichFulfilThe(
jsonContext.createPointer(String.format("/%s", name)),
new PredicateCondition<>(InstanceType.BOOLEAN::isInstance)
)
.isFulfilledBy(schema)
).isFulfilledBy(schema)
) {
return keywordCreator.apply(schema.getBoolean(name));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ private Keyword createKeyword(final JsonObject asJsonObject) {
new JsonPropertyWhichFulfilThe(
createJsonPointer(),
new PredicateCondition<>(InstanceType.INTEGER::isInstance)
)
.isFulfilledBy(asJsonObject)
).isFulfilledBy(asJsonObject)
) {
return keywordCreator.apply(asJsonObject.getJsonNumber(name).bigIntegerValueExact());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ private Keyword createKeyword(final JsonObject schema) {
new JsonPropertyWhichFulfilThe(
jsonContext.createPointer(String.format("/%s", name)),
new PredicateCondition<>(InstanceType.NUMBER::isInstance)
)
.isFulfilledBy(schema)
).isFulfilledBy(schema)
) {
return keywordCreator.apply(schema.getJsonNumber(name).bigDecimalValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ private Keyword createKeyword(final JsonObject schema) {
JsonValue::asJsonArray
)
)
)
.isFulfilledBy(schema)
).isFulfilledBy(schema)
) {
return schema
.getJsonArray(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ private Keyword createKeyword(final JsonObject obj) {
new JsonPropertyWhichFulfilThe(
createJsonPointer(),
new PredicateCondition<>(InstanceType.STRING::isInstance)
)
.isFulfilledBy(obj)
).isFulfilledBy(obj)
) {
return keywordCreator.apply(obj.getString(name()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ public final class OfficialVocabularies implements LazyVocabularies {
private static final Collection<Vocabulary> OFFICEAL_VOCABS;

static {
OFFICEAL_VOCABS =
List.of(
new CoreVocabulary(JSONP),
new ApplicatorVocabulary(),
new ValidationVocabulary(JSONP),
new MetaDataVocabulary(),
new FormatVocabulary(),
new UnevaluatedVocabulary(),
new ContentVocabulary()
);
OFFICEAL_VOCABS = List.of(
new CoreVocabulary(JSONP),
new ApplicatorVocabulary(),
new ValidationVocabulary(JSONP),
new MetaDataVocabulary(),
new FormatVocabulary(),
new UnevaluatedVocabulary(),
new ContentVocabulary()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ private Stream<Map.Entry<String, JsonValue>> findPropertiesForValidation(final J
}

private Collection<String> findPropertyNamesAlreadyConveredByOthersIn(final JsonValue instance) {
return Stream
.of(
additionalPropertiesSchema.owner().keywordByName("properties"),
additionalPropertiesSchema.owner().keywordByName("patternProperties")
)
return Stream.of(
additionalPropertiesSchema.owner().keywordByName("properties"),
additionalPropertiesSchema.owner().keywordByName("patternProperties")
)
.flatMap(Optional::stream)
.map(Keyword::asAnnotation)
.map(anno -> anno.valueFor(instance))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ public final class ApplicatorVocabulary implements Vocabulary {
private final Vocabulary vocab;

public ApplicatorVocabulary() {
this.vocab =
new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/applicator"),
new NamedJsonSchemaKeywordType(PropertiesKeyword.NAME, PropertiesKeyword::new),
new SubSchemaKeywordType(AdditionalPropertiesKeyword.NAME, AdditionalPropertiesKeyword::new),
new NamedJsonSchemaKeywordType(PatternPropertiesKeyword.NAME, PatternPropertiesKeyword::new),
new SubSchemaKeywordType(ItemsKeyword.NAME, ItemsKeyword::new),
new ArraySubSchemaKeywordType(PrefixItemsKeyword.NAME, PrefixItemsKeyword::new)
);
this.vocab = new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/applicator"),
new NamedJsonSchemaKeywordType(PropertiesKeyword.NAME, PropertiesKeyword::new),
new SubSchemaKeywordType(AdditionalPropertiesKeyword.NAME, AdditionalPropertiesKeyword::new),
new NamedJsonSchemaKeywordType(PatternPropertiesKeyword.NAME, PatternPropertiesKeyword::new),
new SubSchemaKeywordType(ItemsKeyword.NAME, ItemsKeyword::new),
new ArraySubSchemaKeywordType(PrefixItemsKeyword.NAME, PrefixItemsKeyword::new)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ class PatternPropertiesKeyword implements Applicator, Annotation {
private final Map<Pattern, JsonSchema> properties;

public PatternPropertiesKeyword(final NamedJsonSchemas properties) {
this.properties =
properties
.schemas()
.stream()
.map(e -> Map.entry(Pattern.compile(e.getKey()), e.getValue()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
this.properties = properties
.schemas()
.stream()
.map(e -> Map.entry(Pattern.compile(e.getKey()), e.getValue()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ public final class CoreVocabulary implements Vocabulary {
private final Vocabulary vocab;

public CoreVocabulary(final JsonProvider jsonContext) {
this.vocab =
new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/core"),
new StringKeywordType(jsonContext, SchemaKeyword.NAME, value -> new SchemaKeyword(URI.create(value))),
new StringKeywordType(jsonContext, IdKeyword.NAME, value -> new IdKeyword(URI.create(value))),
new RefKeywordType(jsonContext),
new NamedJsonSchemaKeywordType(DefsKeyword.NAME, DefsKeyword::new),
new StringKeywordType(jsonContext, CommentKeyword.NAME, CommentKeyword::new),
new VocabularyKeywordType(),
new StringKeywordType(
jsonContext,
DynamicRefKeyword.NAME,
value -> new DynamicRefKeyword(URI.create(value))
)
);
this.vocab = new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/core"),
new StringKeywordType(jsonContext, SchemaKeyword.NAME, value -> new SchemaKeyword(URI.create(value))),
new StringKeywordType(jsonContext, IdKeyword.NAME, value -> new IdKeyword(URI.create(value))),
new RefKeywordType(jsonContext),
new NamedJsonSchemaKeywordType(DefsKeyword.NAME, DefsKeyword::new),
new StringKeywordType(jsonContext, CommentKeyword.NAME, CommentKeyword::new),
new VocabularyKeywordType(),
new StringKeywordType(
jsonContext,
DynamicRefKeyword.NAME,
value -> new DynamicRefKeyword(URI.create(value))
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public String name() {

@Override
public Keyword createKeyword(final JsonSchema schema) {
return new StringKeywordType(jsonContext, RefKeyword.NAME, s -> new RefKeyword(schema, URI.create(s)))
.createKeyword(schema);
return new StringKeywordType(
jsonContext,
RefKeyword.NAME,
s -> new RefKeyword(schema, URI.create(s))
).createKeyword(schema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ public <T extends Media<T>> T printOn(final T media) {
public boolean isValidFor(final JsonValue instance) {
final boolean result;
if (InstanceType.NUMBER.isInstance(instance)) {
result =
allowedValues
.stream()
.filter(InstanceType.NUMBER::isInstance)
.map(JsonNumber.class::cast)
.map(JsonNumber::bigDecimalValue)
.map(BigDecimal::stripTrailingZeros)
.anyMatch(Predicate.isEqual(((JsonNumber) instance).bigDecimalValue().stripTrailingZeros()));
result = allowedValues
.stream()
.filter(InstanceType.NUMBER::isInstance)
.map(JsonNumber.class::cast)
.map(JsonNumber::bigDecimalValue)
.map(BigDecimal::stripTrailingZeros)
.anyMatch(Predicate.isEqual(((JsonNumber) instance).bigDecimalValue().stripTrailingZeros()));
} else {
result = allowedValues.stream().anyMatch(Predicate.isEqual(instance));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ public final class ValidationVocabulary implements Vocabulary {
private final Vocabulary vocab;

public ValidationVocabulary(final JsonProvider jsonContext) {
this.vocab =
new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/validation"),
new TypeKeywordType(),
new ArrayKeywordType(EnumKeyword.NAME, EnumKeyword::new),
new StringKeywordType(jsonContext, PatternKeyword.NAME, PatternKeyword::new),
new IntegerKeywordType(jsonContext, MinLengthKeyword.NAME, MinLengthKeyword::new),
new IntegerKeywordType(jsonContext, MaxLengthKeyword.NAME, MaxLengthKeyword::new),
new NumberKeywordType(jsonContext, ExclusiveMaximumKeyword.NAME, ExclusiveMaximumKeyword::new),
new NumberKeywordType(jsonContext, MultipleOfKeyword.NAME, MultipleOfKeyword::new),
new NumberKeywordType(jsonContext, ExclusiveMinimumKeyword.NAME, ExclusiveMinimumKeyword::new),
new NumberKeywordType(jsonContext, MaximumKeyword.NAME, MaximumKeyword::new),
new NumberKeywordType(jsonContext, MinimumKeyword.NAME, MinimumKeyword::new),
new StringArrayKeywordType(jsonContext, RequiredKeyword.NAME, RequiredKeyword::new),
new IntegerKeywordType(jsonContext, MaxItemsKeyword.NAME, MaxItemsKeyword::new),
new IntegerKeywordType(jsonContext, MinItemsKeyword.NAME, MinItemsKeyword::new),
new BooleanKeywordType(jsonContext, UniqueItemsKeyword.NAME, UniqueItemsKeyword::new)
);
this.vocab = new DefaultVocabulary(
URI.create("https://json-schema.org/draft/2020-12/vocab/validation"),
new TypeKeywordType(),
new ArrayKeywordType(EnumKeyword.NAME, EnumKeyword::new),
new StringKeywordType(jsonContext, PatternKeyword.NAME, PatternKeyword::new),
new IntegerKeywordType(jsonContext, MinLengthKeyword.NAME, MinLengthKeyword::new),
new IntegerKeywordType(jsonContext, MaxLengthKeyword.NAME, MaxLengthKeyword::new),
new NumberKeywordType(jsonContext, ExclusiveMaximumKeyword.NAME, ExclusiveMaximumKeyword::new),
new NumberKeywordType(jsonContext, MultipleOfKeyword.NAME, MultipleOfKeyword::new),
new NumberKeywordType(jsonContext, ExclusiveMinimumKeyword.NAME, ExclusiveMinimumKeyword::new),
new NumberKeywordType(jsonContext, MaximumKeyword.NAME, MaximumKeyword::new),
new NumberKeywordType(jsonContext, MinimumKeyword.NAME, MinimumKeyword::new),
new StringArrayKeywordType(jsonContext, RequiredKeyword.NAME, RequiredKeyword::new),
new IntegerKeywordType(jsonContext, MaxItemsKeyword.NAME, MaxItemsKeyword::new),
new IntegerKeywordType(jsonContext, MinItemsKeyword.NAME, MinItemsKeyword::new),
new BooleanKeywordType(jsonContext, UniqueItemsKeyword.NAME, UniqueItemsKeyword::new)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ void should_return_the_custom_annotation_for_unknow_keyword() {
assertThat(
new BasicVocabulary()
.findKeywordTypeByName("unknow")
.map(keywordType ->
keywordType.createKeyword(
new DefaultJsonSchemaFactory()
.create(Json.createObjectBuilder().add("unknow", JsonValue.FALSE).build())
)
.map(
keywordType ->
keywordType.createKeyword(
new DefaultJsonSchemaFactory()
.create(Json.createObjectBuilder().add("unknow", JsonValue.FALSE).build())
)
)
.map(keyword -> keyword.hasName("unknow")),
OptionalMatchers.isPresentAndIs(true)
Expand Down
Loading

0 comments on commit a76678a

Please sign in to comment.