From 9a898c0e4c80f0d59d6199b222b06210660d79e4 Mon Sep 17 00:00:00 2001 From: Alessia Bardi Date: Wed, 8 Jul 2020 12:52:00 +0200 Subject: [PATCH] Json schema generator --- .../dhp/oa/graph/dump/GenerateJsonSchema.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/GenerateJsonSchema.java diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/GenerateJsonSchema.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/GenerateJsonSchema.java new file mode 100644 index 000000000..ba4bac45b --- /dev/null +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/GenerateJsonSchema.java @@ -0,0 +1,22 @@ +package eu.dnetlib.dhp.oa.graph.dump; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.victools.jsonschema.generator.*; +import eu.dnetlib.dhp.schema.dump.oaf.Result; +import org.junit.jupiter.api.Test; + +public class GenerateJsonSchema { + + @Test + public void generateSchema(){ + SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON) + .with(Option.SCHEMA_VERSION_INDICATOR) + .without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS); + configBuilder.forFields().withDescriptionResolver(field -> "Description of "+field.getDeclaredName()); + SchemaGeneratorConfig config = configBuilder.build(); + SchemaGenerator generator = new SchemaGenerator(config); + JsonNode jsonSchema = generator.generateSchema(Result.class); + + System.out.println(jsonSchema.toString()); +} +}