Search in sources :

Example 11 with AbstractNode

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

the class OpenApi3Validator method validateOperationIdReferences.

protected void validateOperationIdReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
    JsonPointer schemaPointer = JsonPointer.compile("/definitions/link/properties/operationId");
    if (node != null && node.getType() != null && schemaPointer.equals(node.getType().getPointer())) {
        List<AbstractNode> nodes = model.findByType(operationPointer);
        Iterator<AbstractNode> it = nodes.iterator();
        boolean found = false;
        while (it.hasNext() && !found) {
            AbstractNode current = it.next();
            AbstractNode value = current.get("operationId");
            found = value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue());
        }
        if (!found) {
            errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_invalid_operation_id));
        }
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) JsonPointer(com.fasterxml.jackson.core.JsonPointer)

Example 12 with AbstractNode

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

the class OpenApi3Validator method validateSecuritySchemeReferences.

private void validateSecuritySchemeReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
    if (node.getPointerString().matches(".*/security/\\d+")) {
        AbstractNode securitySchemes = model.find(securityPointer);
        if (node.isObject()) {
            for (String field : node.asObject().fieldNames()) {
                AbstractNode securityScheme = securitySchemes.get(field);
                if (securityScheme == null) {
                    String message = Messages.error_invalid_reference_type + " It should be a valid security scheme.";
                    errors.add(error(node.get(field), IMarker.SEVERITY_ERROR, message));
                } else {
                    validateSecuritySchemeScopes(node, field, securityScheme, errors);
                }
            }
        }
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode)

Example 13 with AbstractNode

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

the class Mocks method mockHyperlinkDetector.

public static JsonReferenceHyperlinkDetector mockHyperlinkDetector(final URI uri, final JsonNode document) {
    final JsonDocumentManager manager = mock(JsonDocumentManager.class);
    final IFile file = mock(IFile.class);
    when(file.exists()).thenReturn(true);
    when(manager.getDocument(Mockito.any(URI.class))).thenReturn(document);
    when(manager.getFile(Mockito.any(URI.class))).thenReturn(file);
    return new SwaggerReferenceHyperlinkDetector() {

        // allow running tests as non plugin tests
        protected URI getBaseURI() {
            return uri;
        }

        protected JsonReferenceFactory getFactory() {
            return new JsonReferenceFactory() {

                @Override
                public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
                    JsonReference ref = super.createSimpleReference(baseURI, valueNode);
                    if (ref != null) {
                        ref.setDocumentManager(manager);
                    }
                    return ref;
                }

                @Override
                public JsonReference create(AbstractNode node) {
                    JsonReference ref = super.create(node);
                    ref.setDocumentManager(manager);
                    return ref;
                }

                @Override
                public JsonReference create(JsonNode node) {
                    JsonReference ref = super.create(node);
                    ref.setDocumentManager(manager);
                    return ref;
                }
            };
        }
    };
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) SwaggerReferenceHyperlinkDetector(com.reprezen.swagedit.editor.hyperlinks.SwaggerReferenceHyperlinkDetector) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) JsonReferenceFactory(com.reprezen.swagedit.core.json.references.JsonReferenceFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonDocumentManager(com.reprezen.swagedit.core.json.references.JsonDocumentManager) URI(java.net.URI)

Example 14 with AbstractNode

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

the class JsonContentOutlinePage method update.

protected void update() {
    final IDocument document = documentProvider.getDocument(currentInput);
    if (document instanceof JsonDocument) {
        final Model model = ((JsonDocument) document).getModel();
        if (model == null) {
            return;
        }
        final TreeViewer viewer = getTreeViewer();
        if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
            // we keep all elements that have been previously expanded
            // so the tree stay in the same state between updates.
            final Object[] expandedElements = viewer.getExpandedElements();
            final List<Object> elements = expandedElements != null ? Arrays.asList(expandedElements) : null;
            viewer.setInput(model);
            if (elements != null && !elements.isEmpty()) {
                Iterable<AbstractNode> newElements = filter(model.allNodes(), new Predicate<AbstractNode>() {

                    @Override
                    public boolean apply(AbstractNode node) {
                        return elements.contains(node);
                    }
                });
                viewer.setExpandedElements(toArray(newElements, AbstractNode.class));
            }
        }
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Model(com.reprezen.swagedit.core.model.Model) IDocument(org.eclipse.jface.text.IDocument) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument)

Example 15 with AbstractNode

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

the class Validator method validateModel.

/**
     * Validates the model against with different rules that cannot be verified only by JSON schema validation.
     * 
     * @param model
     * @return errors
     */
protected Set<SwaggerError> validateModel(Model model) {
    final Set<SwaggerError> errors = new HashSet<>();
    if (model != null && model.getRoot() != null) {
        for (AbstractNode node : model.allNodes()) {
            checkArrayTypeDefinition(errors, node);
            checkObjectTypeDefinition(errors, node);
        }
    }
    return errors;
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) HashSet(java.util.HashSet)

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