Search in sources :

Example 1 with JsonSchemaGenerator

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();
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonSchemaGenerator(com.kjetland.jackson.jsonSchema.JsonSchemaGenerator) EndOfFileException(org.jline.reader.EndOfFileException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) UserInterruptException(org.jline.reader.UserInterruptException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) BatfishException(org.batfish.common.BatfishException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonSchemaGenerator (com.kjetland.jackson.jsonSchema.JsonSchemaGenerator)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 BatfishException (org.batfish.common.BatfishException)1 JSONException (org.codehaus.jettison.json.JSONException)1 EndOfFileException (org.jline.reader.EndOfFileException)1 UserInterruptException (org.jline.reader.UserInterruptException)1