Search in sources :

Example 1 with ProcessingReport

use of com.github.fge.jsonschema.core.report.ProcessingReport in project KaiZen-OpenAPI-Editor by RepreZen.

the class Validator method validateAgainstSchema.

public Set<SwaggerError> validateAgainstSchema(ErrorProcessor processor, JsonNode schemaAsJson, JsonNode documentAsJson) {
    final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder().setLoadingConfiguration(loadingConfiguration).freeze();
    final Set<SwaggerError> errors = Sets.newHashSet();
    JsonSchema schema = null;
    try {
        schema = factory.getJsonSchema(schemaAsJson);
    } catch (ProcessingException e) {
        YEditLog.logException(e);
        return errors;
    }
    try {
        ProcessingReport report = schema.validate(documentAsJson, true);
        errors.addAll(processor.processReport(report));
    } catch (ProcessingException e) {
        errors.addAll(processor.processMessage(e.getProcessingMessage()));
    }
    return errors;
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Example 2 with ProcessingReport

use of com.github.fge.jsonschema.core.report.ProcessingReport in project swagger-parser by swagger-api.

the class Issue1Test method parameterWithTypeFileMustHaveCorrectConsumesAndParamType.

@Test
public void parameterWithTypeFileMustHaveCorrectConsumesAndParamType() throws ProcessingException {
    final ProcessingReport report = schema.validate(instance);
    assertFalse(report.isSuccess());
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) Test(org.testng.annotations.Test)

Example 3 with ProcessingReport

use of com.github.fge.jsonschema.core.report.ProcessingReport in project thingsboard by thingsboard.

the class BaseComponentDescriptorService method validate.

@Override
public boolean validate(ComponentDescriptor component, JsonNode configuration) {
    JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
    try {
        if (!component.getConfigurationDescriptor().has("schema")) {
            throw new DataValidationException("Configuration descriptor doesn't contain schema property!");
        }
        JsonNode configurationSchema = component.getConfigurationDescriptor().get("schema");
        ProcessingReport report = validator.validate(configurationSchema, configuration);
        return report.isSuccess();
    } catch (ProcessingException e) {
        throw new IncorrectParameterException(e.getMessage(), e);
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Example 4 with ProcessingReport

use of com.github.fge.jsonschema.core.report.ProcessingReport in project arctic-sea by 52North.

the class JSONValidator method validateAndThrow.

public void validateAndThrow(JsonNode instance, String schema) throws DecodingException {
    ProcessingReport report = JSONValidator.getInstance().validate(instance, schema);
    if (!report.isSuccess()) {
        String message = encode(report, instance);
        LOG.info("Invalid JSON instance:\n{}", message);
        throw new JSONDecodingException(message);
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JSONDecodingException(org.n52.svalbard.decode.json.JSONDecodingException)

Example 5 with ProcessingReport

use of com.github.fge.jsonschema.core.report.ProcessingReport in project arctic-sea by 52North.

the class FieldDecoderTest method validateWithValueAndDecode.

protected SweField validateWithValueAndDecode(ObjectNode json, boolean withValue) throws DecodingException {
    ProcessingReport report = validator.validate(json, withValue ? SchemaConstants.Common.FIELD_WITH_VALUE : SchemaConstants.Common.FIELD);
    if (!report.isSuccess()) {
        System.err.println(validator.encode(report, json));
        fail("Invalid generated field!");
    }
    return decoder.decode(json);
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport)

Aggregations

ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)24 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)11 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)8 JsonSchemaFactory (com.github.fge.jsonschema.main.JsonSchemaFactory)7 IOException (java.io.IOException)7 ProcessingMessage (com.github.fge.jsonschema.core.report.ProcessingMessage)5 JsonValidator (com.github.fge.jsonschema.main.JsonValidator)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Extension (io.syndesis.common.model.extension.Extension)3 Test (org.junit.Test)3 TestExecReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestExecReport)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 ConnectionClosedException (org.apache.http.ConnectionClosedException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Violation (io.syndesis.common.model.Violation)1