use of com.kjetland.jackson.jsonSchema.JsonSchemaGenerator in project batfish by batfish.
the class Client method generateDatamodel.
private void generateDatamodel() {
try {
JsonSchemaGenerator schemaGenNew = new JsonSchemaGenerator(BatfishObjectMapper.mapper());
JsonNode schemaNew = schemaGenNew.generateJsonSchema(Configuration.class);
_logger.output(BatfishObjectMapper.writePrettyString(schemaNew));
// Reflections reflections = new Reflections("org.batfish.datamodel");
// Set<Class<? extends AnswerElement>> classes =
// reflections.getSubTypesOf(AnswerElement.class);
// _logger.outputf("Found %d classes that inherit %s\n",
// classes.toArray().length, "AnswerElement");
//
// File dmDir = Paths.get(_settings.getDatamodelDir()).toFile();
// if (!dmDir.exists()) {
// if (!dmDir.mkdirs()) {
// throw new BatfishException("Could not create directory: " +
// dmDir.getAbsolutePath());
// }
// }
//
// for (Class c : classes) {
// String className = c.getCanonicalName()
// .replaceAll("org\\.batfish\\.datamodel\\.", "")
// .replaceAll("\\.", "-")
// + ".json";
// _logger.outputf("%s --> %s\n", c, className);
// Path file = Paths.get(dmDir.getAbsolutePath(), className);
// try (PrintWriter out = new
// PrintWriter(file.toAbsolutePath().toString())) {
// ObjectMapper mapper = new BatfishObjectMapper();
// JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
// JsonNode schema = schemaGen.generateJsonSchema(c);
// String schemaString = mapper.writeValueAsString(schema);
// out.println(schemaString);
// }
// }
// JsonSchemaGenerator schemaGenNew = new JsonSchemaGenerator(mapper,
// true, JsonSchemaConfig.vanillaJsonSchemaDraft4());
// JsonNode schemaNew =
// schemaGenNew.generateJsonSchema(Configuration.class);
// _logger.output(mapper.writeValueAsString(schemaNew));
// _logger.output("\n");
// JsonNode schemaNew2 =
// schemaGenNew.generateJsonSchema(SchemaTest.Parent.class);
// _logger.output(mapper.writeValueAsString(schemaNew2));
} catch (Exception e) {
_logger.errorf("Could not generate data model: %s", e.getMessage());
e.printStackTrace();
}
}
Aggregations