org.everit.json.schema.EnumSchema Java Examples
The following examples show how to use
org.everit.json.schema.EnumSchema.
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: SchemaDiffVisitor.java From apicurio-registry with Apache License 2.0 | 6 votes |
@Override public void visitConstSchema(ConstSchemaWrapper schema) { Schema orig = original; if (orig instanceof FalseSchema) return; // FalseSchema matches nothing // Const and single-enum equivalency if (orig instanceof EnumSchema) { Set<Object> possibleValues = ((EnumSchema) orig).getPossibleValues(); if (possibleValues.size() == 1) { orig = ConstSchema.builder() .permittedValue(possibleValues.stream().findAny().get()) .build(); } } if (!(orig instanceof ConstSchema)) { ctx.addDifference(SUBSCHEMA_TYPE_CHANGED, orig, schema); return; } schema.accept(new ConstSchemaDiffVisitor(ctx, (ConstSchema) orig)); }
Example #2
Source File: SchemaDiffVisitor.java From apicurio-registry with Apache License 2.0 | 6 votes |
@Override public void visitEnumSchema(EnumSchemaWrapper schema) { Schema orig = original; if (orig instanceof FalseSchema) return; // FalseSchema matches nothing // Const and single-enum equivalency if (orig instanceof ConstSchema) { Object permittedValue = ((ConstSchema) orig).getPermittedValue(); orig = EnumSchema.builder() .possibleValue(permittedValue) .build(); } if (!(orig instanceof EnumSchema)) { ctx.addDifference(SUBSCHEMA_TYPE_CHANGED, orig, schema); return; } schema.accept(new EnumSchemaDiffVisitor(ctx, (EnumSchema) orig)); }
Example #3
Source File: WrapUtil.java From apicurio-registry with Apache License 2.0 | 5 votes |
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: SchemaExtractor.java From json-schema with Apache License 2.0 | 5 votes |
@Override List<Schema.Builder<?>> extract() { if (!containsKey("enum")) { return emptyList(); } EnumSchema.Builder builder = EnumSchema.builder(); List<Object> possibleValues = new ArrayList<>(); require("enum").requireArray().forEach((i, item) -> possibleValues.add(item.unwrap())); builder.possibleValues(possibleValues); return singletonList(builder); }
Example #5
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void enumSchema() { EnumSchema actual = (EnumSchema) SchemaLoader.load(get("enumSchema")); Map<String, Object> expectedObject = new HashMap<>(); expectedObject.put("a", "b"); assertEquals(new HashSet<>(asList(1, 2, "a", expectedObject, null)), new HashSet<>(actual.getPossibleValues())); }
Example #6
Source File: EnumSchemaDiffVisitor.java From apicurio-registry with Apache License 2.0 | 4 votes |
public EnumSchemaDiffVisitor(DiffContext ctx, EnumSchema original) { this.ctx = ctx; this.original = original; }
Example #7
Source File: EnumSchemaWrapper.java From apicurio-registry with Apache License 2.0 | 4 votes |
public EnumSchemaWrapper(EnumSchema wrapped) { this.wrapped = wrapped; }
Example #8
Source File: SchemaDiff.java From nakadi with MIT License | 4 votes |
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 #9
Source File: EnumSchemaDiff.java From nakadi with MIT License | 4 votes |
static void recursiveCheck( final EnumSchema enumSchemaOriginal, final EnumSchema enumSchemaUpdate, final SchemaDiffState state) { if (!enumSchemaOriginal.getPossibleValues().equals(enumSchemaUpdate.getPossibleValues())) { state.addChange("enum", ENUM_ARRAY_CHANGED); } }