use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OperationContextType method collectProposals.
@Override
public Collection<Proposal> collectProposals(Model model, IPath path) {
final Collection<Proposal> results = Lists.newArrayList();
final List<AbstractNode> nodes = model.findByType(operationPointer);
for (AbstractNode node : nodes) {
String pointer = node.getPointerString();
String basePath = (path != null ? path.toString() : "") + "#" + pointer;
String key = node.getProperty();
String value = basePath;
String encoded = URLUtils.encodeURL(value);
results.add(new Proposal("\"" + encoded + "\"", key, null, value));
}
return results;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OperationIdContextType method collectProposals.
@Override
public Collection<Proposal> collectProposals(Model model, IPath path) {
final Collection<Proposal> results = Lists.newArrayList();
final List<AbstractNode> nodes = model.findByType(operationPointer);
for (AbstractNode node : nodes) {
AbstractNode value = node.get("operationId");
if (value != null && value.asValue().getValue() instanceof String) {
String key = (String) value.asValue().getValue();
results.add(new Proposal(key, key, null, value.getProperty()));
}
}
return results;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class DefinitionHyperlinkDetector method getRequiredPropertyPath.
protected JsonPointer getRequiredPropertyPath(JsonDocument doc, HyperlinkInfo info, JsonPointer pointer) {
Matcher matcher = Pattern.compile(REQUIRED_PATTERN).matcher(pointer.toString());
String containerPath = null;
if (matcher.find()) {
containerPath = matcher.group(1);
}
if (emptyToNull(containerPath) == null) {
return null;
}
AbstractNode container = doc.getModel().find(JsonPointer.compile(containerPath));
if (container.get("properties") != null && container.get("properties").get(info.text) != null) {
return container.get("properties").get(info.text).getPointer();
} else {
return null;
}
}
use of com.reprezen.swagedit.core.model.AbstractNode 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.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceValidator method findTarget.
protected AbstractNode findTarget(JsonDocument doc, URI baseURI, JsonReference reference) {
Model model = doc.getModel();
AbstractNode valueNode = model.find(reference.getPointer());
if (valueNode == null) {
// Try to load the referenced node from an external document
JsonNode externalDoc = reference.getDocument(doc, baseURI);
if (externalDoc != null) {
try {
Model externalModel = Model.parse(model.getSchema(), externalDoc);
valueNode = externalModel.find(reference.getPointer());
} catch (Exception e) {
// fail to parse the model or the pointer
return null;
}
}
}
return valueNode;
}
Aggregations