This commit is contained in:
Miriam Baglioni 2020-07-29 17:06:53 +02:00
parent b96dedb56b
commit d0ff2a56fb
1 changed files with 16 additions and 12 deletions

View File

@ -1,22 +1,26 @@
package eu.dnetlib.dhp.oa.graph.dump; package eu.dnetlib.dhp.oa.graph.dump;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.github.victools.jsonschema.generator.*; import com.github.victools.jsonschema.generator.*;
import eu.dnetlib.dhp.schema.dump.oaf.Result; import eu.dnetlib.dhp.schema.dump.oaf.Result;
import org.junit.jupiter.api.Test;
public class GenerateJsonSchema { public class GenerateJsonSchema {
@Test @Test
public void generateSchema(){ public void generateSchema() {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON) SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7,
.with(Option.SCHEMA_VERSION_INDICATOR) OptionPreset.PLAIN_JSON)
.without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS); .with(Option.SCHEMA_VERSION_INDICATOR)
configBuilder.forFields().withDescriptionResolver(field -> "Description of "+field.getDeclaredName()); .without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS);
SchemaGeneratorConfig config = configBuilder.build(); configBuilder.forFields().withDescriptionResolver(field -> "Description of " + field.getDeclaredName());
SchemaGenerator generator = new SchemaGenerator(config); SchemaGeneratorConfig config = configBuilder.build();
JsonNode jsonSchema = generator.generateSchema(Result.class); SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(Result.class);
System.out.println(jsonSchema.toString()); System.out.println(jsonSchema.toString());
} }
} }