Skip to content

Instantly share code, notes, and snippets.

@fge
Created December 27, 2012 23:29
Show Gist options
  • Save fge/4393138 to your computer and use it in GitHub Desktop.
Save fge/4393138 to your computer and use it in GitHub Desktop.
Declaring "indexed"
package org.eel.kitchen.jsonschema;
import com.fasterxml.jackson.databind.JsonNode;
import org.eel.kitchen.jsonschema.main.JsonSchema;
import org.eel.kitchen.jsonschema.main.JsonSchemaFactory;
import org.eel.kitchen.jsonschema.main.Keyword;
import org.eel.kitchen.jsonschema.metaschema.KeywordRegistries;
import org.eel.kitchen.jsonschema.metaschema.KeywordRegistry;
import org.eel.kitchen.jsonschema.metaschema.SchemaURIs;
import org.eel.kitchen.jsonschema.ref.JsonRef;
import org.eel.kitchen.jsonschema.report.ValidationReport;
import org.eel.kitchen.jsonschema.syntax.SyntaxChecker;
import org.eel.kitchen.jsonschema.syntax.TypeOnlySyntaxChecker;
import org.eel.kitchen.jsonschema.util.JsonLoader;
import org.eel.kitchen.jsonschema.util.NodeType;
import java.io.IOException;
public final class AsargentoTestCase
{
public static void main(final String... args)
throws IOException
{
final JsonNode schema1 = JsonLoader.fromResource("/asargento/schema1");
final JsonNode schema2 = JsonLoader.fromResource("/asargento/schema2");
final JsonSchemaFactory factory = JsonSchemaFactory.defaultFactory();
final JsonSchema jsonSchema1 = factory.fromSchema(schema1);
ValidationReport report;
report = jsonSchema1.validate(schema1);
if (report.isSuccess())
System.out.println("Validates OK [1]");
report = jsonSchema1.validate(schema2);
if (report.isSuccess())
System.out.println("Validates OK");
final JsonRef ref = SchemaURIs.draftV3HyperSchema();
final KeywordRegistry registry = KeywordRegistries.draftV3HyperSchema();
final String name = "indexed";
final SyntaxChecker checker
= new TypeOnlySyntaxChecker(name, NodeType.BOOLEAN);
final Keyword keyword = Keyword.withName(name)
.withSyntaxChecker(checker).build();
registry.addKeyword(keyword);
final JsonSchemaFactory factory2 = new JsonSchemaFactory.Builder()
.addKeywordRegistry(ref, registry, true).build();
report = factory2.fromSchema(schema2).validate(schema2);
System.out.println(report.isSuccess());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment