Search in sources :

Example 1 with Node

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));
        }
    });
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node)

Example 2 with Node

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;
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode)

Example 3 with Node

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;
}
Also used : SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) ObjectNode(com.reprezen.swagedit.core.model.ObjectNode) ValueNode(com.reprezen.swagedit.core.model.ValueNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ArrayNode(com.reprezen.swagedit.core.model.ArrayNode) Node(org.yaml.snakeyaml.nodes.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) IOException(java.io.IOException) ParserException(org.yaml.snakeyaml.parser.ParserException)

Example 4 with Node

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;
}
Also used : SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) ObjectNode(com.reprezen.swagedit.core.model.ObjectNode) ValueNode(com.reprezen.swagedit.core.model.ValueNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ArrayNode(com.reprezen.swagedit.core.model.ArrayNode) Node(org.yaml.snakeyaml.nodes.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with Node

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);
}
Also used : ErrorProcessor(com.reprezen.swagedit.core.validation.ErrorProcessor) Node(org.yaml.snakeyaml.nodes.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) Before(org.junit.Before)

Aggregations

Node (org.yaml.snakeyaml.nodes.Node)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)4 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)3 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)2 ArrayNode (com.reprezen.swagedit.core.model.ArrayNode)2 ObjectNode (com.reprezen.swagedit.core.model.ObjectNode)2 ValueNode (com.reprezen.swagedit.core.model.ValueNode)2 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)2 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 ErrorProcessor (com.reprezen.swagedit.core.validation.ErrorProcessor)1 IOException (java.io.IOException)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Before (org.junit.Before)1 ParserException (org.yaml.snakeyaml.parser.ParserException)1