use of com.networknt.schema.JsonSchema in project SONG by overture-stack.
the class JsonSchemaUtils method getJsonSchemaFromClasspath.
@SneakyThrows
public static JsonSchema getJsonSchemaFromClasspath(String fileName) {
JsonSchemaFactory factory = new JsonSchemaFactory();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
JsonSchema schema = factory.getSchema(is);
return schema;
}
use of com.networknt.schema.JsonSchema in project SONG by overture-stack.
the class JsonSchemaUtils method getJsonSchema.
@SneakyThrows
public static JsonSchema getJsonSchema(JsonNode node) {
JsonSchemaFactory factory = new JsonSchemaFactory();
JsonSchema schema = factory.getSchema(node);
return schema;
}
use of com.networknt.schema.JsonSchema in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final Object value, final JsonNode schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schema);
final JsonNode content = Config.getInstance().getMapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
use of com.networknt.schema.JsonSchema in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final Object value, final Object schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema));
if (api != null) {
if (this.definitions == null) {
this.definitions = Json.mapper().readTree(Json.pretty(api.getDefinitions()));
}
((ObjectNode) schemaObject).set(DEFINITIONS_FIELD, this.definitions);
}
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject);
final JsonNode content = Json.mapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (JsonParseException e) {
return new Status(VALIDATOR_SCHEMA_INVALID_JSON, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
Aggregations