use of org.everit.json.schema.SchemaException in project nakadi by zalando.
the class EventTypeService method validateSchema.
private void validateSchema(final EventTypeBase eventType) throws InvalidEventTypeException {
try {
final String eventTypeSchema = eventType.getSchema().getSchema();
JsonUtils.checkEventTypeSchemaValid(eventTypeSchema);
final JSONObject schemaAsJson = new JSONObject(eventTypeSchema);
final Schema schema = SchemaLoader.load(schemaAsJson);
if (eventType.getCategory() == EventCategory.BUSINESS && schema.definesProperty("#/metadata")) {
throw new InvalidEventTypeException("\"metadata\" property is reserved");
}
if (featureToggleService.isFeatureEnabled(CHECK_PARTITIONS_KEYS)) {
validatePartitionKeys(schema, eventType);
}
if (eventType.getCompatibilityMode() == CompatibilityMode.COMPATIBLE) {
validateJsonSchemaConstraints(schemaAsJson);
}
} catch (final JSONException e) {
throw new InvalidEventTypeException("schema must be a valid json");
} catch (final SchemaException e) {
throw new InvalidEventTypeException("schema must be a valid json-schema");
}
}
Aggregations