use of org.yaml.snakeyaml.nodes.ScalarNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class ValidationUtil method findNode.
/*
* Returns the yaml node that matches the given path.
*
* The path is given as a list of String. The Node matching the path is found by traversing the children of the node
* pass as first parameter.
*/
private static Node findNode(MappingNode root, List<String> paths) {
if (paths.isEmpty())
return root;
String path = paths.get(0);
if (path.startsWith("/")) {
path = path.substring(1, path.length());
}
final List<String> next = paths.subList(1, paths.size());
// ~1 is use to escape /
if (path.contains("~1")) {
path = path.replaceAll("~1", "/");
}
for (NodeTuple child : root.getValue()) {
if (child.getKeyNode() instanceof ScalarNode) {
ScalarNode scalar = (ScalarNode) child.getKeyNode();
if (scalar.getValue().equals(path)) {
return findNode(child, next);
}
}
}
return root;
}
Aggregations