org.everit.json.schema.NullSchema Java Examples
The following examples show how to use
org.everit.json.schema.NullSchema.
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: SchemaExtractor.java From json-schema with Apache License 2.0 | 6 votes |
private Schema.Builder<?> loadForExplicitType(String typeString) { switch (typeString) { case "string": return buildStringSchema().requiresString(true); case "integer": return buildNumberSchema().requiresInteger(true); case "number": return buildNumberSchema(); case "boolean": return BooleanSchema.builder(); case "null": return NullSchema.builder(); case "array": return buildArraySchema(); case "object": return buildObjectSchema(); default: throw new SchemaException(schemaJson.ls.locationOfCurrentObj(), format("unknown type: [%s]", typeString)); } }
Example #2
Source File: SchemaDiffVisitor.java From apicurio-registry with Apache License 2.0 | 5 votes |
@Override public void visitNullSchema(NullSchemaWrapper schema) { if (original instanceof FalseSchema) return; // FalseSchema matches nothing if (!(original instanceof NullSchema)) { ctx.addDifference(SUBSCHEMA_TYPE_CHANGED, original, schema); return; } schema.accept(new NullSchemaDiffVisitor(ctx, (NullSchema) original)); }
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: JsonSchemaFromFieldDescriptorsGenerator.java From restdocs-raml with MIT License | 5 votes |
private void handleEndOfPath(ObjectSchema.Builder builder, String propertyName, FieldDescriptor fieldDescriptor) { if (fieldDescriptor.isIgnored()) { // We don't need to render anything } else { if (isRequired(fieldDescriptor)) { builder.addRequiredProperty(propertyName); } if (fieldDescriptor.getType().equals(JsonFieldType.NULL) || fieldDescriptor.getType().equals(JsonFieldType.VARIES)) { builder.addPropertySchema(propertyName, NullSchema.builder() .description((String) fieldDescriptor.getDescription()) .build()); } else if (fieldDescriptor.getType().equals(JsonFieldType.OBJECT)) { builder.addPropertySchema(propertyName, ObjectSchema.builder() .description((String) fieldDescriptor.getDescription()) .build()); } else if (fieldDescriptor.getType().equals(JsonFieldType.ARRAY)) { builder.addPropertySchema(propertyName, ArraySchema.builder() .description((String) fieldDescriptor.getDescription()) .build()); } else if (fieldDescriptor.getType().equals(JsonFieldType.BOOLEAN)) { builder.addPropertySchema(propertyName, BooleanSchema.builder() .description((String) fieldDescriptor.getDescription()) .build()); } else if (fieldDescriptor.getType().equals(JsonFieldType.NUMBER)) { builder.addPropertySchema(propertyName, NumberSchema.builder() .description((String) fieldDescriptor.getDescription()) .build()); } else if (fieldDescriptor.getType().equals(JsonFieldType.STRING)) { builder.addPropertySchema(propertyName, StringSchema.builder() .minLength(minLengthString(fieldDescriptor)) .maxLength(maxLengthString(fieldDescriptor)) .description((String) fieldDescriptor.getDescription()) .build()); } else { throw new IllegalArgumentException("unknown field type " + fieldDescriptor.getType()); } } }
Example #5
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void tupleSchema() { ArraySchema actual = (ArraySchema) SchemaLoader.load(get("tupleSchema")); assertFalse(actual.permitsAdditionalItems()); assertNull(actual.getAllItemSchema()); assertEquals(2, actual.getItemSchemas().size()); assertEquals(BooleanSchema.INSTANCE, actual.getItemSchemas().get(0)); assertEquals(NullSchema.INSTANCE, actual.getItemSchemas().get(1)); }
Example #6
Source File: ArraySchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void arraySchema() { ArraySchema actual = (ArraySchema) SchemaLoader.load(get("arraySchema")); assertNotNull(actual); assertEquals(2, actual.getMinItems().intValue()); assertEquals(3, actual.getMaxItems().intValue()); assertTrue(actual.needsUniqueItems()); assertEquals(NullSchema.INSTANCE, actual.getAllItemSchema()); }
Example #7
Source File: JSONPrinterTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void printSchemaMap() { HashMap<Number, Schema> input = new HashMap<Number, Schema>(); input.put(2, NullSchema.INSTANCE); subject().printSchemaMap(input); assertEquals("{\"2\":" + NullSchema.INSTANCE.toString() + "}", buffer.toString()); }
Example #8
Source File: NullSchemaDiffVisitor.java From apicurio-registry with Apache License 2.0 | 4 votes |
public NullSchemaDiffVisitor(DiffContext ctx, NullSchema original) { this.ctx = ctx; this.original = original; }
Example #9
Source File: NullSchemaWrapper.java From apicurio-registry with Apache License 2.0 | 4 votes |
public NullSchemaWrapper(NullSchema wrapped) { this.wrapped = wrapped; }
Example #10
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 4 votes |
@Test public void nullSchema() { NullSchema actual = (NullSchema) SchemaLoader.load(get("nullSchema")); assertNotNull(actual); }