use of org.yaml.snakeyaml.nodes.Node in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReconcilingStrategy method calculatePositions.
protected void calculatePositions() {
if (!(document instanceof JsonDocument))
return;
final Node yaml = ((JsonDocument) document).getYaml();
if (!(yaml instanceof MappingNode)) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
editor.updateFoldingStructure(calculatePositions((MappingNode) yaml));
}
});
}
use of org.yaml.snakeyaml.nodes.Node in project KaiZen-OpenAPI-Editor by RepreZen.
the class ValidationUtil method getLine.
/*
* Returns the line for which an error message has been produced.
*
* The error message is a JSON object that contains the path to the invalid node. The path is accessible via
* instance.pointer. The path is in the forms: - /{id} - /{id}/~{nb} - /{id}/~{id2}
*
* The line number is computed by after parsing the yaml content with the yaml parser. This latter returns a tree of
* Node, each corresponding to a yaml construct and including a position.
*
* The Node matching the path is found by the methods findNode().
*/
public static int getLine(JsonNode error, Node yamlTree) {
String path = getInstancePointer(error);
if (path == null || path.isEmpty())
return 1;
path = path.substring(1, path.length());
String[] strings = path.split("/");
if (yamlTree instanceof MappingNode) {
MappingNode mn = (MappingNode) yamlTree;
Node findNode = findNode(mn, Arrays.asList(strings));
if (findNode != null) {
return findNode.getStartMark().getLine() + 1;
}
}
return 1;
}
use of org.yaml.snakeyaml.nodes.Node in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method validate.
public Set<SwaggerError> validate(JsonDocument document, URI baseURI) {
Set<SwaggerError> errors = Sets.newHashSet();
JsonNode jsonContent = null;
try {
jsonContent = document.asJson();
} catch (Exception e) {
YEditLog.logException(e);
}
if (jsonContent != null) {
Node yaml = document.getYaml();
if (yaml != null) {
errors.addAll(validateAgainstSchema(new ErrorProcessor(yaml, document.getSchema().getRootType().getContent()), document));
errors.addAll(validateModel(document.getModel()));
errors.addAll(checkDuplicateKeys(yaml));
errors.addAll(referenceValidator.validate(baseURI, document));
}
}
return errors;
}
use of org.yaml.snakeyaml.nodes.Node in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method checkDuplicateKeys.
/*
* Finds all duplicate keys in all objects present in the YAML document.
*/
protected Set<SwaggerError> checkDuplicateKeys(Node document) {
HashMultimap<Pair<Node, String>, Node> acc = HashMultimap.<Pair<Node, String>, Node>create();
collectDuplicates(document, acc);
Set<SwaggerError> errors = Sets.newHashSet();
for (Pair<Node, String> key : acc.keys()) {
Set<Node> duplicates = acc.get(key);
if (duplicates.size() > 1) {
for (Node duplicate : duplicates) {
errors.add(createDuplicateError(key.getValue(), duplicate));
}
}
}
return errors;
}
use of org.yaml.snakeyaml.nodes.Node in project KaiZen-OpenAPI-Editor by RepreZen.
the class ErrorProcessorTest method setUp.
@Before
public void setUp() {
Node document = null;
processor = new ErrorProcessor(document, null);
}
Aggregations