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) };
}
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;
}
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()]);
}
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;
}
Aggregations