use of com.nextdoor.bender.config.BenderConfig.BenderSchema in project bender by Nextdoor.
the class CreateSchema method main.
public static void main(String[] args) throws ParseException, InterruptedException, IOException {
/*
* Parse cli arguments
*/
Options options = new Options();
options.addOption(Option.builder().longOpt("out-file").hasArg().desc("Filename to output schema to. Default: schema.json").build());
options.addOption(Option.builder().longOpt("docson").hasArg(false).desc("Create a schema that is able to be read by docson").build());
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String filename = cmd.getOptionValue("out-file", "schema.json");
/*
* Write schema
*/
BenderSchema schema = new BenderSchema();
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
JsonNode node = schema.getSchema();
if (cmd.hasOption("docson")) {
modifyNode(node);
}
mapper.writeValue(new File(filename), node);
}
use of com.nextdoor.bender.config.BenderConfig.BenderSchema in project bender by Nextdoor.
the class ValidateSchema method main.
public static void main(String[] args) throws ParseException, InterruptedException, IOException {
/*
* Parse cli arguments
*/
Options options = new Options();
options.addOption(Option.builder().longOpt("schema").hasArg().desc("Filename to output schema to. Default: schema.json").build());
options.addOption(Option.builder().longOpt("configs").hasArgs().desc("List of config files to validate against schema.").build());
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String schemaFilename = cmd.getOptionValue("schema", "schema.json");
String[] configFilenames = cmd.getOptionValues("configs");
/*
* Validate config files against schema
*/
BenderSchema schema = new BenderSchema(new File(schemaFilename));
boolean hasFailures = false;
for (String configFilename : configFilenames) {
StringBuilder sb = new StringBuilder();
Files.lines(Paths.get(configFilename), StandardCharsets.UTF_8).forEach(p -> sb.append(p + "\n"));
System.out.println("Attempting to validate " + configFilename);
try {
ObjectMapper mapper = BenderConfig.getObjectMapper(configFilename);
BenderConfig.validate(sb.toString(), mapper, schema);
System.out.println("Valid");
} catch (ConfigurationException e) {
System.out.println("Invalid");
e.printStackTrace();
}
}
if (hasFailures) {
System.exit(1);
}
}
use of com.nextdoor.bender.config.BenderConfig.BenderSchema in project bender by Nextdoor.
the class WriteSchema method main.
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
String filename = args[0];
new File(filename).getParentFile().mkdirs();
BenderSchema schema = new BenderSchema();
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
JsonNode node = schema.getSchema();
mapper.writeValue(new File(filename), node);
}
Aggregations