use of com.github.fge.jsonschema.core.report.ProcessingMessage in project swagger-parser by swagger-api.
the class SwaggerJsonValidator method fillMessages.
private static boolean fillMessages(final ProcessingReport report, final MessageBuilder builder) {
final Severity severity = LEVEL_MAP.get(report.getLogLevel());
final ArrayNode node = JacksonUtils.nodeFactory().arrayNode();
for (final ProcessingMessage processingMessage : report) {
node.add(processingMessage.asJson());
}
final String reportAsString = JacksonUtils.prettyPrint(node);
final Message message = new Message("", reportAsString, severity);
builder.append(message);
return report.isSuccess();
}
use of com.github.fge.jsonschema.core.report.ProcessingMessage in project ocvn by devgateway.
the class ReleaseExportTest method testReleaseExportIsValid.
@Test
public void testReleaseExportIsValid() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
final File file = new File(classLoader.getResource("json/award-release-test.json").getFile());
final JsonImport releaseJsonImport = new ReleaseJsonImport(releaseRepository, file, false);
final Release release = (Release) releaseJsonImport.importObject();
final MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/ocds/release/ocid/" + release.getOcid()).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andReturn();
final String content = result.getResponse().getContentAsString();
final JsonNode jsonNodeResponse = JsonLoader.fromString(content);
final OcdsSchemaValidatorService.ProcessingReportWithNode processingReport = ocdsSchemaValidator.validate(jsonNodeResponse);
if (!processingReport.getReport().isSuccess()) {
for (ProcessingMessage processingMessage : processingReport.getReport()) {
logger.error(">>> processingMessage: \n" + processingMessage);
}
}
Assert.assertEquals("Is the release valid?", true, processingReport.getReport().isSuccess());
}
use of com.github.fge.jsonschema.core.report.ProcessingMessage in project arctic-sea by 52North.
the class JSONValidator method encode.
public String encode(ProcessingReport report, JsonNode instance) {
ObjectNode objectNode = Json.nodeFactory().objectNode();
objectNode.set(JSONConstants.INSTANCE, instance);
ArrayNode errors = objectNode.putArray(JSONConstants.ERRORS);
for (ProcessingMessage m : report) {
errors.add(m.asJson());
}
return Json.print(objectNode);
}
use of com.github.fge.jsonschema.core.report.ProcessingMessage in project syndesis by syndesisio.
the class SwaggerHelper method validateJSonSchema.
private static SwaggerModelInfo validateJSonSchema(final String specification, final Swagger model) {
try {
final JsonNode specRoot = convertToJson(specification);
final ProcessingReport report = SWAGGER_2_0_SCHEMA.validate(specRoot);
final List<Violation> errors = new ArrayList<>();
final List<Violation> warnings = new ArrayList<>();
for (final ProcessingMessage message : report) {
final boolean added = append(errors, message, Optional.of("error"));
if (!added) {
append(warnings, message, Optional.empty());
}
}
return new SwaggerModelInfo.Builder().errors(errors).warnings(warnings).model(model).resolvedSpecification(specification).build();
} catch (IOException | ProcessingException ex) {
LOG.error("Unable to load the schema file embedded in the artifact", ex);
return new SwaggerModelInfo.Builder().addError(new Violation.Builder().error("error").property("").message("Unable to load the swagger schema file embedded in the artifact").build()).build();
}
}
use of com.github.fge.jsonschema.core.report.ProcessingMessage in project service-proxy by membrane.
the class JSONValidator method validateMessage.
public Outcome validateMessage(Exchange exc, InputStream body, Charset charset, String source) throws Exception {
List<String> errors;
boolean success = true;
try {
JsonNode node = JsonLoader.fromReader(new InputStreamReader(body, charset));
ProcessingReport report = schema.validateUnchecked(node);
success = report.isSuccess();
errors = new ArrayList<String>();
for (ProcessingMessage message : report) errors.add(message.getMessage());
} catch (JsonParseException e) {
success = false;
errors = new ArrayList<String>();
errors.add(e.getMessage());
}
if (success) {
valid.incrementAndGet();
return Outcome.CONTINUE;
}
if (failureHandler == FailureHandler.VOID) {
StringBuilder message = new StringBuilder();
message.append(source);
message.append(": ");
for (String error : errors) {
message.append(error);
message.append(";");
}
exc.setProperty("error", message.toString());
invalid.incrementAndGet();
return Outcome.ABORT;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonGenerator jg = new JsonFactory().createGenerator(baos);
jg.writeStartObject();
jg.writeStringField("source", source);
jg.writeArrayFieldStart("errors");
for (String message : errors) jg.writeString(message);
jg.close();
if (failureHandler != null) {
failureHandler.handleFailure(new String(baos.toByteArray(), UTF8), exc);
exc.setResponse(Response.badRequest().contentType("application/json;charset=utf-8").body("{\"error\":\"error\"}".getBytes(UTF8)).build());
} else {
exc.setResponse(Response.badRequest().contentType("application/json;charset=utf-8").body(baos.toByteArray()).build());
}
invalid.incrementAndGet();
return Outcome.ABORT;
}
Aggregations