use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class PathParamHyperlinkDetector method findParameterPath.
private Iterable<JsonPointer> findParameterPath(JsonDocument doc, JsonPointer basePath, String parameter) {
AbstractNode parent = doc.getModel().find(basePath);
if (parent == null || !parent.isObject()) {
return Lists.newArrayList();
}
List<JsonPointer> paths = new ArrayList<>();
for (HttpMethod method : HttpMethod.values()) {
String mName = method.name().toLowerCase();
if (parent.get(mName) == null) {
continue;
}
AbstractNode parameters = parent.get(mName).get("parameters");
if (parameters != null && parameters.isArray()) {
for (int i = 0; i < parameters.size(); i++) {
AbstractNode current = parameters.get(i);
if (JsonReference.isReference(current)) {
JsonPointer ptr = JsonReference.getPointer(current.asObject());
AbstractNode resolved = doc.getModel().find(ptr);
if (resolved != null && resolved.isObject() && resolved.get("name") != null) {
if (parameter.equals(resolved.get("name").asValue().getValue())) {
paths.add(ptr);
}
}
} else if (current.isObject() && current.get("name") != null) {
if (parameter.equals(current.get("name").asValue().getValue())) {
paths.add(JsonPointer.compile(basePath + "/" + mName + "/parameters/" + i));
}
}
}
}
}
return paths;
}
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 JsonDocument method getRegion.
public IRegion getRegion(JsonPointer pointer) {
Model model = getModel();
if (model == null) {
return null;
}
AbstractNode node = model.find(pointer);
if (node == null) {
return new Region(0, 0);
}
Position position = node.getPosition(this);
return new Region(position.getOffset(), position.getLength());
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class Mocks method mockJsonReferenceFactory.
public static JsonReferenceFactory mockJsonReferenceFactory(final Map<URI, JsonNode> entries) {
final IFile file = mock(IFile.class);
when(file.exists()).thenReturn(true);
return new JsonReferenceFactory() {
public JsonReference create(AbstractNode node) {
JsonReference ref = super.create(node);
ref.setDocumentManager(new JsonDocumentManager() {
@Override
public IFile getFile(URI uri) {
return file;
}
@Override
public JsonNode getDocument(URI uri) {
return entries.get(uri);
}
});
return ref;
}
};
}
use of com.reprezen.swagedit.core.model.AbstractNode 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