use of com.reprezen.swagedit.core.model.Model 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()) {
List<AbstractNode> newElements = new ArrayList<>();
model.allNodes().forEach(node -> {
if (elements.contains(node))
newElements.add(node);
});
viewer.setExpandedElements(newElements.toArray());
}
}
}
}
use of com.reprezen.swagedit.core.model.Model 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;
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method validate.
public Set<SwaggerError> validate(JsonDocument document, URI baseURI) {
Set<SwaggerError> errors = new HashSet<>();
JsonNode jsonContent = null;
try {
jsonContent = document.asJson();
} catch (Exception e) {
jsonContent = null;
}
if (jsonContent != null) {
Node yaml = document.getYaml();
Model model = document.getModel();
if (yaml != null && model != null) {
errors.addAll(getSchemaValidator().validate(document));
errors.addAll(validateDocument(baseURI, document));
errors.addAll(checkDuplicateKeys(yaml));
errors.addAll(getReferenceValidator().validate(baseURI, document, model));
}
}
return errors;
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceFactory method createSimpleReference.
/**
* Returns a simple reference if the value node points to a definition inside the same document.
*
* @param baseURI
* @param value
* @return reference
*/
public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
if (valueNode == null || valueNode.isArray() || valueNode.isObject()) {
return null;
}
final Object value = valueNode.asValue().getValue();
if (!(value instanceof String)) {
return null;
}
String stringValue = (String) value;
if (StringUtils.emptyToNull(stringValue) == null || stringValue.startsWith("#") || stringValue.contains("/")) {
return null;
}
final Model model = valueNode.getModel();
if (model != null) {
JsonPointer ptr = JsonPointer.compile("/definitions/" + value);
AbstractNode target = model.find(ptr);
if (target != null) {
return new JsonReference.SimpleReference(baseURI, ptr, valueNode);
}
}
return null;
}
Aggregations