Search in sources :

Example 26 with AbstractNode

use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class Validator method checkMissingRequiredProperties.

/**
 * This method checks that the required values for the object type definition contains only valid properties.
 *
 * @param errors
 * @param node
 */
protected void checkMissingRequiredProperties(Set<SwaggerError> errors, AbstractNode node) {
    if (node.get("required") instanceof ArrayNode) {
        ArrayNode required = node.get("required").asArray();
        AbstractNode properties = node.get("properties");
        if (properties == null) {
            errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_missing_properties));
        } else {
            for (AbstractNode prop : required.elements()) {
                if (prop instanceof ValueNode) {
                    ValueNode valueNode = prop.asValue();
                    String value = valueNode.getValue().toString();
                    if (properties.get(value) == null) {
                        errors.add(error(valueNode, IMarker.SEVERITY_ERROR, String.format(Messages.error_required_properties, value)));
                    }
                }
            }
        }
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) ValueNode(com.reprezen.swagedit.core.model.ValueNode) ArrayNode(com.reprezen.swagedit.core.model.ArrayNode)

Example 27 with AbstractNode

use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceFactory method createSimpleReference.

/**
 * Returns a simple reference if the value node points to a definition inside the same document.
 *
 * @param baseURI
 * @param value
 * @return reference
 */
public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
    if (valueNode == null || valueNode.isArray() || valueNode.isObject()) {
        return null;
    }
    final Object value = valueNode.asValue().getValue();
    if (!(value instanceof String)) {
        return null;
    }
    String stringValue = (String) value;
    if (Strings.emptyToNull(stringValue) == null || stringValue.startsWith("#") || stringValue.contains("/")) {
        return null;
    }
    final Model model = valueNode.getModel();
    if (model != null) {
        JsonPointer ptr = JsonPointer.compile("/definitions/" + value);
        AbstractNode target = model.find(ptr);
        if (target != null) {
            return new JsonReference.SimpleReference(baseURI, ptr, valueNode);
        }
    }
    return null;
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) Model(com.reprezen.swagedit.core.model.Model) JsonPointer(com.fasterxml.jackson.core.JsonPointer)

Example 28 with AbstractNode

use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceValidator method validateType.

/**
 * This method checks that referenced objects are of expected type as defined in the schema.
 *
 * @param doc
 *            current document
 * @param node
 *            node holding the reference
 * @param reference
 *            actual reference
 * @param errors
 *            current set of errors
 */
protected void validateType(JsonDocument doc, URI baseURI, AbstractNode node, JsonReference reference, Set<SwaggerError> errors) {
    AbstractNode target = findTarget(doc, baseURI, reference);
    TypeDefinition type = node.getType();
    boolean isValidType = type != null && type.validate(target);
    if (!isValidType) {
        errors.add(createReferenceError(SEVERITY_WARNING, error_invalid_reference_type, reference));
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) TypeDefinition(com.reprezen.swagedit.core.schema.TypeDefinition)

Example 29 with AbstractNode

use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class SecuritySchemeContextType method collectProposals.

@Override
public Collection<Proposal> collectProposals(Model model, IPath path) {
    final Collection<Proposal> results = Lists.newArrayList();
    AbstractNode securitySchemes = model.find(securityPointer);
    if (securitySchemes != null && securitySchemes.isObject()) {
        for (String key : securitySchemes.asObject().fieldNames()) {
            results.add(new Proposal(key, key, null, securitySchemes.getProperty()));
        }
    }
    return results;
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) Proposal(com.reprezen.swagedit.core.assist.Proposal)

Aggregations

AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)29 Model (com.reprezen.swagedit.core.model.Model)6 JsonPointer (com.fasterxml.jackson.core.JsonPointer)5 JsonReference (com.reprezen.swagedit.core.json.references.JsonReference)5 URI (java.net.URI)5 IFile (org.eclipse.core.resources.IFile)5 IRegion (org.eclipse.jface.text.IRegion)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)4 Proposal (com.reprezen.swagedit.core.assist.Proposal)3 JsonDocumentManager (com.reprezen.swagedit.core.json.references.JsonDocumentManager)3 TypeDefinition (com.reprezen.swagedit.core.schema.TypeDefinition)3 Matcher (java.util.regex.Matcher)3 SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)2 JsonReferenceFactory (com.reprezen.swagedit.core.json.references.JsonReferenceFactory)2 ArrayNode (com.reprezen.swagedit.core.model.ArrayNode)2 ComplexTypeDefinition (com.reprezen.swagedit.core.schema.ComplexTypeDefinition)2 MultipleTypeDefinition (com.reprezen.swagedit.core.schema.MultipleTypeDefinition)2 Position (org.eclipse.jface.text.Position)2 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1