Json schema generator

This commit is contained in:
Alessia Bardi 2020-07-08 12:52:00 +02:00
parent 636f9ce7d6
commit 9a898c0e4c
1 changed files with 22 additions and 0 deletions

View File

@ -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());
}
}