Search in sources :

Example 1 with SchemaException

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");
    }
}
Also used : SchemaException(org.everit.json.schema.SchemaException) InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) JSONObject(org.json.JSONObject) Schema(org.everit.json.schema.Schema) JSONException(org.json.JSONException)

Aggregations

Schema (org.everit.json.schema.Schema)1 SchemaException (org.everit.json.schema.SchemaException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 InvalidEventTypeException (org.zalando.nakadi.exceptions.InvalidEventTypeException)1