Search in sources :

Example 1 with SwaggerHyperlink

use of com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class DefinitionHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    JsonPointer targetPath;
    if (pointer.toString().matches(REQUIRED_PATTERN)) {
        targetPath = getRequiredPropertyPath(doc, info, pointer);
    } else {
        targetPath = getTagDefinitionPath(doc, info, pointer);
    }
    if (targetPath == null) {
        return null;
    }
    IRegion target = doc.getRegion(targetPath);
    if (target == null) {
        return null;
    }
    return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) JsonPointer(com.fasterxml.jackson.core.JsonPointer) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with SwaggerHyperlink

use of com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class LinkOperationHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    Model model = doc.getModel();
    AbstractNode node = model.find(pointer);
    List<AbstractNode> nodes = model.findByType(JsonPointer.compile("/definitions/operation"));
    Iterator<AbstractNode> it = nodes.iterator();
    AbstractNode found = null;
    while (it.hasNext() && found == null) {
        AbstractNode current = it.next();
        AbstractNode value = current.get("operationId");
        if (value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue())) {
            found = value;
        }
    }
    if (found != null) {
        IRegion target = doc.getRegion(found.getPointer());
        if (target != null) {
            return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
        }
    }
    return null;
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Model(com.reprezen.swagedit.core.model.Model) IRegion(org.eclipse.jface.text.IRegion)

Example 3 with SwaggerHyperlink

use of com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class PathParamHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    // find selected parameter
    Matcher matcher = PARAMETER_PATTERN.matcher(info.text);
    String parameter = null;
    int start = 0, end = 0;
    while (matcher.find() && parameter == null) {
        if (matcher.start() <= info.column && matcher.end() >= info.column) {
            parameter = matcher.group(1);
            start = matcher.start();
            end = matcher.end();
        }
    }
    // no parameter found
    if (emptyToNull(parameter) == null) {
        return null;
    }
    Iterable<JsonPointer> targetPaths = findParameterPath(doc, pointer, parameter);
    IRegion linkRegion = new Region(info.getOffset() + start, end - start);
    List<IHyperlink> links = new ArrayList<>();
    for (JsonPointer path : targetPaths) {
        IRegion target = doc.getRegion(path);
        if (target != null) {
            links.add(new SwaggerHyperlink(parameter, viewer, linkRegion, target));
        }
    }
    return links.isEmpty() ? null : links.toArray(new IHyperlink[links.size()]);
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) Matcher(java.util.regex.Matcher) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) ArrayList(java.util.ArrayList) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) JsonPointer(com.fasterxml.jackson.core.JsonPointer) IRegion(org.eclipse.jface.text.IRegion)

Example 4 with SwaggerHyperlink

use of com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class SecuritySchemeHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    Matcher matcher = PATTERN.matcher(pointer.toString());
    String link = matcher.find() ? matcher.group(1) : null;
    if (link != null) {
        Model model = doc.getModel();
        AbstractNode securityScheme = model.find("/components/securitySchemes/" + link);
        if (securityScheme != null) {
            IRegion target = doc.getRegion(securityScheme.getPointer());
            if (target != null) {
                return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
            }
        }
    }
    return null;
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) Matcher(java.util.regex.Matcher) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Model(com.reprezen.swagedit.core.model.Model) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)4 IRegion (org.eclipse.jface.text.IRegion)4 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)4 JsonPointer (com.fasterxml.jackson.core.JsonPointer)2 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)2 Model (com.reprezen.swagedit.core.model.Model)2 Matcher (java.util.regex.Matcher)2 ArrayList (java.util.ArrayList)1 Region (org.eclipse.jface.text.Region)1