2022-08-03 11:42:56 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.github.imifou.jsonschema.module.addon.AddonModule;
|
|
|
|
import com.github.victools.jsonschema.generator.*;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.ExecCreateSchemas;
|
|
|
|
import eu.dnetlib.dhp.eosc.model.EoscResult;
|
|
|
|
import eu.dnetlib.dhp.oa.model.graph.GraphResult;
|
|
|
|
|
|
|
|
//@Disabled
|
|
|
|
class GenerateJsonSchema {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
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(GraphResult.class);
|
|
|
|
|
|
|
|
System.out.println(jsonSchema.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void generateSchema2() {
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
AddonModule module = new AddonModule();
|
|
|
|
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper,
|
|
|
|
SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON)
|
|
|
|
.with(module)
|
|
|
|
.with(Option.SCHEMA_VERSION_INDICATOR)
|
|
|
|
.without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS);
|
|
|
|
SchemaGeneratorConfig config = configBuilder.build();
|
|
|
|
SchemaGenerator generator = new SchemaGenerator(config);
|
|
|
|
JsonNode jsonSchema = generator.generateSchema(GraphResult.class);
|
|
|
|
|
|
|
|
System.out.println(jsonSchema.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void generateSchema3() throws JsonProcessingException {
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
AddonModule module = new AddonModule();
|
|
|
|
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper,
|
|
|
|
SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON)
|
|
|
|
.with(module)
|
|
|
|
.with(Option.SCHEMA_VERSION_INDICATOR)
|
|
|
|
.without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS);
|
|
|
|
SchemaGeneratorConfig config = configBuilder.build();
|
|
|
|
SchemaGenerator generator = new SchemaGenerator(config);
|
|
|
|
JsonNode jsonSchema = generator.generateSchema(EoscResult.class);
|
|
|
|
|
2022-09-13 12:10:47 +02:00
|
|
|
System.out.println(new ObjectMapper().writeValueAsString(jsonSchema));
|
2022-08-03 11:42:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void generateJsonSchema3() throws IOException {
|
|
|
|
|
|
|
|
ExecCreateSchemas.main(new String[] {});
|
|
|
|
}
|
|
|
|
}
|