use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method checkMissingRequiredProperties.
/**
* This method checks that the required values for the object type definition contains only valid properties.
*
* @param errors
* @param node
*/
protected void checkMissingRequiredProperties(Set<SwaggerError> errors, AbstractNode node) {
if (node.get("required") instanceof ArrayNode) {
ArrayNode required = node.get("required").asArray();
AbstractNode properties = node.get("properties");
if (properties == null) {
errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_missing_properties));
} else {
for (AbstractNode prop : required.elements()) {
if (prop instanceof ValueNode) {
ValueNode valueNode = prop.asValue();
String value = valueNode.getValue().toString();
if (properties.get(value) == null) {
errors.add(error(valueNode, IMarker.SEVERITY_ERROR, String.format(Messages.error_required_properties, value)));
}
}
}
}
}
}
use of com.reprezen.swagedit.core.model.AbstractNode 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 (Strings.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;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceValidator method validateType.
/**
* This method checks that referenced objects are of expected type as defined in the schema.
*
* @param doc
* current document
* @param node
* node holding the reference
* @param reference
* actual reference
* @param errors
* current set of errors
*/
protected void validateType(JsonDocument doc, URI baseURI, AbstractNode node, JsonReference reference, Set<SwaggerError> errors) {
AbstractNode target = findTarget(doc, baseURI, reference);
TypeDefinition type = node.getType();
boolean isValidType = type != null && type.validate(target);
if (!isValidType) {
errors.add(createReferenceError(SEVERITY_WARNING, error_invalid_reference_type, reference));
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class SecuritySchemeContextType method collectProposals.
@Override
public Collection<Proposal> collectProposals(Model model, IPath path) {
final Collection<Proposal> results = Lists.newArrayList();
AbstractNode securitySchemes = model.find(securityPointer);
if (securitySchemes != null && securitySchemes.isObject()) {
for (String key : securitySchemes.asObject().fieldNames()) {
results.add(new Proposal(key, key, null, securitySchemes.getProperty()));
}
}
return results;
}
Aggregations