org.everit.json.schema.EmptySchema Java Examples

The following examples show how to use org.everit.json.schema.EmptySchema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaLoader.java    From json-schema with Apache License 2.0 6 votes vote down vote up
private Schema.Builder loadSchemaObject(JsonObject o) {
    AdjacentSchemaExtractionState postExtractionState = runSchemaExtractors(o);
    Collection<Schema.Builder<?>> extractedSchemas = postExtractionState.extractedSchemaBuilders();
    Schema.Builder effectiveReturnedSchema;
    if (extractedSchemas.isEmpty()) {
        effectiveReturnedSchema = EmptySchema.builder();
    } else if (extractedSchemas.size() == 1) {
        effectiveReturnedSchema = extractedSchemas.iterator().next();
    } else {
        Collection<Schema> built = extractedSchemas.stream()
                .map(Schema.Builder::build)
                .map(Schema.class::cast)
                .collect(toList());
        effectiveReturnedSchema = CombinedSchema.allOf(built).isSynthetic(true);
    }
    AdjacentSchemaExtractionState postCommonPropLoadingState = loadCommonSchemaProperties(effectiveReturnedSchema, postExtractionState);
    Map<String, Object> unprocessed = postCommonPropLoadingState.projectedSchemaJson().toMap();
    effectiveReturnedSchema.unprocessedProperties(unprocessed);
    return effectiveReturnedSchema;
}
 
Example #2
Source File: PrimitiveSchemaDiffVisitor.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
private void emptyTrueSchema(SchemaWrapper wrapper) {
    // This is spelled explicitly for clarity, and in case the library changes.
    if (!(EmptySchema.INSTANCE.equals(original) // ||
        // TrueSchema.INSTANCE.equals(original)
    )) {
        ctx.addDifference(SUBSCHEMA_TYPE_CHANGED_TO_EMPTY_OR_TRUE, original, wrapper);
        // Change to empty schema is backwards compatible
    }
}
 
Example #3
Source File: WrapUtil.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
public static SchemaWrapper wrap(Schema schema) {
    if (schema == null)
        return null;

    if (schema instanceof ObjectSchema) {
        return new ObjectSchemaWrapper((ObjectSchema) schema);
    } else if (schema instanceof ArraySchema) {
        return new ArraySchemaWrapper((ArraySchema) schema);
    } else if (schema instanceof StringSchema) {
        return new StringSchemaWrapper((StringSchema) schema);
    } else if (schema instanceof EmptySchema && !(schema instanceof TrueSchema)) {
        return new EmptySchemaWrapper((EmptySchema) schema);
    } else if (schema instanceof TrueSchema) {
        return new TrueSchemaWrapper((TrueSchema) schema);
    } else if (schema instanceof FalseSchema) {
        return new FalseSchemaWrapper((FalseSchema) schema);
    } else if (schema instanceof BooleanSchema) {
        return new BooleanSchemaWrapper((BooleanSchema) schema);
    } else if (schema instanceof ConstSchema) {
        return new ConstSchemaWrapper((ConstSchema) schema);
    } else if (schema instanceof EnumSchema) {
        return new EnumSchemaWrapper((EnumSchema) schema);
    } else if (schema instanceof NullSchema) {
        return new NullSchemaWrapper((NullSchema) schema);
    } else if (schema instanceof NotSchema) {
        return new NotSchemaWrapper((NotSchema) schema);
    } else if (schema instanceof ReferenceSchema) {
        return new ReferenceSchemaWrapper((ReferenceSchema) schema);
    } else if (schema instanceof CombinedSchema) {
        return new CombinedSchemaWrapper((CombinedSchema) schema);
    } else if (schema instanceof ConditionalSchema) {
        return new ConditionalSchemaWrapper((ConditionalSchema) schema);
    } else if (schema instanceof NumberSchema) {
        return new NumberSchemaWrapper((NumberSchema) schema);
    } else {
        throw new IllegalStateException("No wrapper for an underlying schema type '" + schema.getClass() + "': " + schema);
    }
}
 
Example #4
Source File: EmptySchemaWrapper.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
public EmptySchemaWrapper(EmptySchema wrapped) {
    this.wrapped = wrapped;
}
 
Example #5
Source File: SchemaDiff.java    From nakadi with MIT License 4 votes vote down vote up
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;
    }

    if (originalIn == 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 if (typeNarrowed(originalIn, updateIn)) {
            state.addChange(TYPE_NARROWED);
            return;
        } 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);
        }
    });
}
 
Example #6
Source File: SchemaDiff.java    From nakadi with MIT License 4 votes vote down vote up
private static boolean typeNarrowed(final Schema originalIn, final Schema updateIn) {
    return originalIn instanceof EmptySchema && !(updateIn instanceof EmptySchema);
}
 
Example #7
Source File: SchemaLoaderTest.java    From json-schema with Apache License 2.0 4 votes vote down vote up
@Test
public void emptySchema() {
    assertTrue(SchemaLoader.load(get("emptySchema")) instanceof EmptySchema);
}
 
Example #8
Source File: SchemaLoaderTest.java    From json-schema with Apache License 2.0 4 votes vote down vote up
@Test
public void emptySchemaWithDefault() {
    EmptySchema actual = (EmptySchema) SchemaLoader.load(get("emptySchemaWithDefault"));
    assertNotNull(actual);
}