Skip to content

Commit

Permalink
Merge pull request #129 from sebastian-toepfer/smaller_fixes
Browse files Browse the repository at this point in the history
enable all default schemas at default
  • Loading branch information
sebastian-toepfer authored Jun 6, 2024
2 parents e94a19b + b84f3bf commit 5a9515d
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 17 deletions.
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 @@ -107,4 +107,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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.FormatVocabulary;
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;
Expand All @@ -49,7 +49,7 @@ public final class OfficialVocabularies implements LazyVocabularies {
new ApplicatorVocabulary(),
new ValidationVocabulary(JSONP),
new MetaDataVocabulary(),
new FormatVocabulary(),
new FormatAnnotationVocabulary(),
new UnevaluatedVocabulary(),
new ContentVocabulary()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
* source: https://www.learnjsonschema.com/2020-12/format-annotation/
* spec: https://json-schema.org/draft/2020-12/json-schema-validation.html#section-7.2.1
*/
public final class FormatVocabulary implements Vocabulary {
public final class FormatAnnotationVocabulary implements Vocabulary {

private final Vocabulary vocab;

public FormatVocabulary() {
public FormatAnnotationVocabulary() {
this.vocab = new DefaultVocabulary(URI.create("https://json-schema.org/draft/2020-12/vocab/format-annotation"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,12 @@ void should_return_empty_if_given_name_not_resolve_to_a_valid_schematype() {
void should_be_printable() {
assertThat(schema.printOn(new HashMapMedia()), allOf(hasEntry("type", "array"), hasKey("items")));
}

@Test
void should_has_a_nice_to_string() {
assertThat(
new DefaultJsonObjectSchema(Json.createObjectBuilder().add("type", "string").build()).toString(),
is("{\"type\":\"string\"}")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ void should_be_printable() {
hasEntry("type", "array")
);
}

@Test
void should_has_a_nice_to_string() {
assertThat(
new DefaultJsonSubSchema(
new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("test", JsonValue.TRUE).build()),
new DefaultJsonSchemaFactory().create(Json.createObjectBuilder().add("type", "array").build())
).toString(),
is("{\"type\":\"array\"}")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ void should_be_valid_for_everything(final JsonValue value) {
void should_be_printable() {
assertThat(new EmptyJsonSchema().printOn(new HashMapMedia()), anEmptyMap());
}

@Test
void should_has_a_nice_to_string() {
assertThat(new EmptyJsonSchema().toString(), is("{}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.hamcrest.Matchers.not;

import jakarta.json.JsonValue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

Expand All @@ -38,4 +39,9 @@ class FalseJsonSchemaTest {
void should_be_invalid_for_everything(final JsonValue value) {
assertThat(new FalseJsonSchema().validator().isValid(value), is(not(true)));
}

@Test
void should_has_a_nice_to_string() {
assertThat(new FalseJsonSchema().toString(), is("false"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@
import io.github.sebastiantoepfer.ddd.media.core.HashMapMedia;
import io.github.sebastiantoepfer.jsonschema.JsonSchema;
import io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory;
import io.github.sebastiantoepfer.jsonschema.core.keyword.type.StringKeywordType;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import jakarta.json.spi.JsonProvider;
import java.net.URI;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -112,13 +109,4 @@ void should_be_printable() {
(Matcher) hasEntry(is("$ref"), is("#"))
);
}

private static Keyword createKeywordFrom(final JsonObject json) {
final JsonSchema schema = new DefaultJsonSchemaFactory().create(json);
return new StringKeywordType(
JsonProvider.provider(),
"$ref",
s -> new RefKeyword(schema, URI.create(s))
).createKeyword(schema);
}
}

0 comments on commit 5a9515d

Please sign in to comment.