Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable all default schemas at default #129

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}