Search in sources :

Example 1 with CombinedSchema

use of org.everit.json.schema.CombinedSchema in project nakadi by zalando.

the class SchemaDiff method recursiveCheck.

static void recursiveCheck(final Schema originalIn, final Schema updateIn, final SchemaDiffState state) {
    if (originalIn == null && updateIn == null) {
        return;
    }
    if (updateIn == null) {
        state.addChange(SCHEMA_REMOVED);
        return;
    }
    final Schema original;
    final Schema update;
    if (!originalIn.getClass().equals(updateIn.getClass())) {
        // Tricky part. EmptySchema is the same as an empty ObjectSchema.
        if (originalIn instanceof EmptySchema && updateIn instanceof ObjectSchema) {
            original = replaceWithEmptyObjectSchema(originalIn);
            update = updateIn;
        } else {
            state.addChange(TYPE_CHANGED);
            return;
        }
    } else {
        original = originalIn;
        update = updateIn;
    }
    state.analyzeSchema(originalIn, () -> {
        if (!Objects.equals(original.getId(), update.getId())) {
            state.addChange(ID_CHANGED);
        }
        if (!Objects.equals(original.getTitle(), update.getTitle())) {
            state.addChange(TITLE_CHANGED);
        }
        if (!Objects.equals(original.getDescription(), update.getDescription())) {
            state.addChange(DESCRIPTION_CHANGED);
        }
        if (original instanceof StringSchema) {
            StringSchemaDiff.recursiveCheck((StringSchema) original, (StringSchema) update, state);
        } else if (original instanceof NumberSchema) {
            NumberSchemaDiff.recursiveCheck((NumberSchema) original, (NumberSchema) update, state);
        } else if (original instanceof EnumSchema) {
            EnumSchemaDiff.recursiveCheck((EnumSchema) original, (EnumSchema) update, state);
        } else if (original instanceof CombinedSchema) {
            CombinedSchemaDiff.recursiveCheck((CombinedSchema) original, (CombinedSchema) update, state);
        } else if (original instanceof ObjectSchema) {
            ObjectSchemaDiff.recursiveCheck((ObjectSchema) original, (ObjectSchema) update, state);
        } else if (original instanceof ArraySchema) {
            ArraySchemaDiff.recursiveCheck((ArraySchema) original, (ArraySchema) update, state);
        } else if (original instanceof ReferenceSchema) {
            ReferenceSchemaDiff.recursiveCheck((ReferenceSchema) original, (ReferenceSchema) update, state);
        }
    });
}
Also used : ReferenceSchema(org.everit.json.schema.ReferenceSchema) ArraySchema(org.everit.json.schema.ArraySchema) EmptySchema(org.everit.json.schema.EmptySchema) ObjectSchema(org.everit.json.schema.ObjectSchema) EmptySchema(org.everit.json.schema.EmptySchema) NumberSchema(org.everit.json.schema.NumberSchema) CombinedSchema(org.everit.json.schema.CombinedSchema) ArraySchema(org.everit.json.schema.ArraySchema) ReferenceSchema(org.everit.json.schema.ReferenceSchema) EnumSchema(org.everit.json.schema.EnumSchema) ObjectSchema(org.everit.json.schema.ObjectSchema) StringSchema(org.everit.json.schema.StringSchema) Schema(org.everit.json.schema.Schema) EnumSchema(org.everit.json.schema.EnumSchema) CombinedSchema(org.everit.json.schema.CombinedSchema) StringSchema(org.everit.json.schema.StringSchema) NumberSchema(org.everit.json.schema.NumberSchema)

Aggregations

ArraySchema (org.everit.json.schema.ArraySchema)1 CombinedSchema (org.everit.json.schema.CombinedSchema)1 EmptySchema (org.everit.json.schema.EmptySchema)1 EnumSchema (org.everit.json.schema.EnumSchema)1 NumberSchema (org.everit.json.schema.NumberSchema)1 ObjectSchema (org.everit.json.schema.ObjectSchema)1 ReferenceSchema (org.everit.json.schema.ReferenceSchema)1 Schema (org.everit.json.schema.Schema)1 StringSchema (org.everit.json.schema.StringSchema)1