use of com.reprezen.swagedit.core.validation.SwaggerError in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3Validator method validate.
@Override
public Set<SwaggerError> validate(JsonDocument document, URI baseURI) {
final Set<SwaggerError> errors = super.validate(document, baseURI);
final long nbOfErrors = errors.stream().filter(e -> e.getLevel() == SEVERITY_ERROR).count();
// and option in UI is enable.
if (isAdvancedValidation() && nbOfErrors == 0) {
try {
OpenApi3 result = new OpenApi3Parser().parse(document.get(), baseURI.toURL(), true);
for (ValidationItem item : result.getValidationResults().getItems()) {
PositionInfo pos = item.getPositionInfo();
int line = pos != null ? pos.getLine() : 1;
errors.add(new SwaggerError(line, getSeverity(item.getSeverity()), item.getMsg()));
}
} catch (Exception e) {
Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage()));
}
}
return errors;
}
use of com.reprezen.swagedit.core.validation.SwaggerError 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 baseURI
* document base URI
* @param reference
* actual reference
* @param sources
* list of node being source of the reference
* @param schemas
* cache of JSON schemas
* @param errors
* current set of errors
*/
protected Set<SwaggerError> validateType(JsonDocument doc, URI baseURI, JsonReference reference, Collection<AbstractNode> sources) {
Set<SwaggerError> errors = new HashSet<>();
JsonNode target = findTarget(doc, baseURI, reference);
// To avoid performing even more cycles, the sources are grouped by their type.
// Validation is done only once for each sources having same type.
Map<String, List<AbstractNode>> sourceTypes = groupSourcesByType(sources);
for (String type : sourceTypes.keySet()) {
Set<JsonNode> report = schemaValidator.validate(target, type);
if (!report.isEmpty()) {
errors.addAll(createReferenceError(SEVERITY_WARNING, error_invalid_reference_type, sources));
}
}
return errors;
}
use of com.reprezen.swagedit.core.validation.SwaggerError in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3ReferenceValidator method validateType.
@Override
protected Set<SwaggerError> validateType(JsonDocument doc, URI baseURI, JsonReference reference, Collection<AbstractNode> sources) {
Set<SwaggerError> errors = new HashSet<>();
Map<String, List<AbstractNode>> sourceTypes = groupSourcesByType(sources);
JsonNode target = findTarget(doc, baseURI, reference);
for (String type : sourceTypes.keySet()) {
boolean isOperationValidation = linkTypePointer.equals(type);
String ptr = isOperationValidation ? operationTypePointer.toString() : type;
String message = isOperationValidation ? error_invalid_operation_ref : error_invalid_reference_type;
Set<JsonNode> report = getSchemaValidator().validate(target, ptr);
if (!report.isEmpty()) {
errors.addAll(createReferenceError(SEVERITY_WARNING, message, sources));
}
}
return errors;
}
use of com.reprezen.swagedit.core.validation.SwaggerError in project KaiZen-OpenAPI-Editor by RepreZen.
the class ErrorProcessorTest method testProcessNode_WithSingleError.
@Test
public void testProcessNode_WithSingleError() throws Exception {
JsonNode fixture = mapper.readTree(Paths.get("resources", "error-1.json").toFile());
Set<SwaggerError> errors = processor.processMessageNode(fixture);
assertEquals(1, errors.size());
assertTrue(getOnlyElement(errors) instanceof SwaggerError);
}
use of com.reprezen.swagedit.core.validation.SwaggerError in project KaiZen-OpenAPI-Editor by RepreZen.
the class ErrorProcessorTest method testProcessNode_WithOneOfError.
@Test
public void testProcessNode_WithOneOfError() throws Exception {
JsonNode fixture = mapper.readTree(Paths.get("resources", "error-2.json").toFile());
Set<SwaggerError> errors = processor.processMessageNode(fixture);
assertEquals(1, errors.size());
assertTrue(getOnlyElement(errors) instanceof SwaggerError.MultipleSwaggerError);
}
Aggregations