use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3ReferenceValidator method validateType.
@Override
protected void validateType(JsonDocument doc, URI baseURI, AbstractNode node, JsonReference reference, Set<SwaggerError> errors) {
if (linkTypePointer.equals(node.getType().getPointer())) {
AbstractNode target = findTarget(doc, baseURI, reference);
boolean isValidType = isValidOperation(target);
if (!isValidType) {
errors.add(createReferenceError(SEVERITY_WARNING, error_invalid_operation_ref, reference));
}
} else {
super.validateType(doc, baseURI, node, reference, errors);
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3Validator method validateSecuritySchemeScopes.
private void validateSecuritySchemeScopes(AbstractNode node, String name, AbstractNode securityScheme, Set<SwaggerError> errors) {
String type = getType(securityScheme);
if (type == null) {
return;
}
boolean shouldHaveScopes = oauthScopes.contains(type);
List<String> scopes = getSecurityScopes(securityScheme);
AbstractNode values = node.get(name);
if (values.isArray()) {
ArrayNode scopeValues = values.asArray();
if (scopeValues.size() > 0 && !shouldHaveScopes) {
String message = String.format(Messages.error_scope_should_be_empty, name, type, name);
errors.add(error(node.get(name), IMarker.SEVERITY_ERROR, message));
} else if (scopeValues.size() == 0 && shouldHaveScopes) {
String message = String.format(Messages.error_scope_should_not_be_empty, name, type);
errors.add(error(node.get(name), IMarker.SEVERITY_ERROR, message));
} else {
for (AbstractNode scope : scopeValues.elements()) {
try {
String scopeName = (String) scope.asValue().getValue();
if (!scopes.contains(scopeName)) {
String message = String.format(Messages.error_invalid_scope_reference, scopeName, name);
errors.add(error(scope, IMarker.SEVERITY_ERROR, message));
}
} catch (Exception e) {
// Invalid scope name type.
// No need to create an error, it will be handle by the schema validation.
}
}
}
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class PathParamHyperlinkDetector method findParameterPath.
/*
* Returns a Map having for keys a method name and for value the pointer to the parameter.
*/
private Map<String, JsonPointer> findParameterPath(JsonDocument doc, JsonPointer basePath, String parameter) {
Map<String, JsonPointer> paths = Maps.newHashMap();
AbstractNode parent = doc.getModel().find(basePath);
if (parent == null || !parent.isObject()) {
return paths;
}
for (String method : methods) {
if (parent.get(method) == null) {
continue;
}
AbstractNode parameters = parent.get(method).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.put(method, ptr);
}
}
} else if (current.isObject() && current.get("name") != null) {
if (parameter.equals(current.get("name").asValue().getValue())) {
paths.put(method, JsonPointer.compile(basePath + "/" + method + "/parameters/" + i));
}
}
}
}
}
return paths;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class ReferenceHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
URI baseURI = getBaseURI();
AbstractNode node = doc.getModel().find(pointer);
JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
if (reference == null) {
reference = getFactory().create(node);
}
if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
return null;
}
if (reference.isLocal()) {
IRegion target = doc.getRegion(reference.getPointer());
if (target == null) {
return null;
}
return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
} else {
URI resolved;
try {
resolved = baseURI.resolve(reference.getUri());
} catch (IllegalArgumentException e) {
// the given string violates RFC 2396
return null;
}
IFile file = DocumentUtils.getWorkspaceFile(resolved);
if (file != null && file.exists()) {
return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
}
}
return null;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class ComponentContextType method isReference.
protected boolean isReference(Model model, JsonPointer pointer) {
AbstractNode contextNode = model.find(pointer);
if (contextNode == null) {
return false;
}
TypeDefinition type = contextNode.getType();
if (type instanceof MultipleTypeDefinition) {
// MultipleTypeDefinition is a special case, it happens when several properties match a property
for (TypeDefinition nestedType : ((MultipleTypeDefinition) type).getMultipleTypes()) {
if (getReferencePointerString().equals(nestedType.getPointer().toString())) {
return true;
}
}
}
JsonPointer pointerToType = type.getPointer();
if (pointerToType == null) {
return false;
}
return getReferencePointerString().equals(pointerToType.toString());
}
Aggregations