use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3Validator method validateOperationIdReferences.
protected void validateOperationIdReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
JsonPointer schemaPointer = JsonPointer.compile("/definitions/link/properties/operationId");
if (node != null && node.getType() != null && schemaPointer.equals(node.getType().getPointer())) {
List<AbstractNode> nodes = model.findByType(operationPointer);
Iterator<AbstractNode> it = nodes.iterator();
boolean found = false;
while (it.hasNext() && !found) {
AbstractNode current = it.next();
AbstractNode value = current.get("operationId");
found = value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue());
}
if (!found) {
errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_invalid_operation_id));
}
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3Validator method validateSecuritySchemeReferences.
private void validateSecuritySchemeReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
if (node.getPointerString().matches(".*/security/\\d+")) {
AbstractNode securitySchemes = model.find(securityPointer);
if (node.isObject()) {
for (String field : node.asObject().fieldNames()) {
AbstractNode securityScheme = securitySchemes.get(field);
if (securityScheme == null) {
String message = Messages.error_invalid_reference_type + " It should be a valid security scheme.";
errors.add(error(node.get(field), IMarker.SEVERITY_ERROR, message));
} else {
validateSecuritySchemeScopes(node, field, securityScheme, errors);
}
}
}
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class Mocks method mockHyperlinkDetector.
public static JsonReferenceHyperlinkDetector mockHyperlinkDetector(final URI uri, final JsonNode document) {
final JsonDocumentManager manager = mock(JsonDocumentManager.class);
final IFile file = mock(IFile.class);
when(file.exists()).thenReturn(true);
when(manager.getDocument(Mockito.any(URI.class))).thenReturn(document);
when(manager.getFile(Mockito.any(URI.class))).thenReturn(file);
return new SwaggerReferenceHyperlinkDetector() {
// allow running tests as non plugin tests
protected URI getBaseURI() {
return uri;
}
protected JsonReferenceFactory getFactory() {
return new JsonReferenceFactory() {
@Override
public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
JsonReference ref = super.createSimpleReference(baseURI, valueNode);
if (ref != null) {
ref.setDocumentManager(manager);
}
return ref;
}
@Override
public JsonReference create(AbstractNode node) {
JsonReference ref = super.create(node);
ref.setDocumentManager(manager);
return ref;
}
@Override
public JsonReference create(JsonNode node) {
JsonReference ref = super.create(node);
ref.setDocumentManager(manager);
return ref;
}
};
}
};
}
use of com.reprezen.swagedit.core.model.AbstractNode 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()) {
Iterable<AbstractNode> newElements = filter(model.allNodes(), new Predicate<AbstractNode>() {
@Override
public boolean apply(AbstractNode node) {
return elements.contains(node);
}
});
viewer.setExpandedElements(toArray(newElements, AbstractNode.class));
}
}
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method validateModel.
/**
* Validates the model against with different rules that cannot be verified only by JSON schema validation.
*
* @param model
* @return errors
*/
protected Set<SwaggerError> validateModel(Model model) {
final Set<SwaggerError> errors = new HashSet<>();
if (model != null && model.getRoot() != null) {
for (AbstractNode node : model.allNodes()) {
checkArrayTypeDefinition(errors, node);
checkObjectTypeDefinition(errors, node);
}
}
return errors;
}
Aggregations