use of com.microsoft.azure.maven.prompt.SchemaValidator in project azure-maven-plugins by microsoft.
the class ConfigurationPrompter method initialize.
public void initialize() throws IOException, InvalidConfigurationException {
prompt = new DefaultPrompter();
validator = new SchemaValidator();
templates = new HashMap<>();
commonVariables = new HashMap<>();
final Yaml yaml = new Yaml();
final Set<String> resourceNames = new HashSet<>();
try (final InputStream inputStream = this.getClass().getResourceAsStream("/MessageTemplates.yaml")) {
final Iterable<Object> rules = yaml.loadAll(inputStream);
for (final Object rule : rules) {
final Map<String, Object> map = (Map<String, Object>) rule;
templates.put((String) map.get("id"), map);
if (map.containsKey("resource")) {
resourceNames.add((String) map.get("resource"));
}
}
}
for (final String resourceName : resourceNames) {
final ObjectNode resourceSchema = (ObjectNode) JsonLoader.fromResource("/schema/" + resourceName + ".json");
if (!resourceSchema.has("properties")) {
throw new InvalidConfigurationException(String.format("Bad schema for %s: missing properties field.", resourceName));
}
final ObjectNode propertiesNode = (ObjectNode) resourceSchema.get("properties");
IteratorUtils.forEach(propertiesNode.fields(), prop -> {
try {
this.validator.collectSingleProperty(resourceName, prop.getKey(), prop.getValue());
} catch (JsonProcessingException e) {
throw Lombok.sneakyThrow(e);
}
});
}
}
Aggregations