Java Code Examples for org.everit.json.schema.NullSchema

The following examples show how to use org.everit.json.schema.NullSchema. These examples are extracted from open source projects. 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 Project: json-schema   Author: everit-org   File: SchemaExtractor.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: apicurio-registry   Author: Apicurio   File: SchemaDiffVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: apicurio-registry   Author: Apicurio   File: WrapUtil.java    License: 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 Project: restdocs-raml   Author: ePages-de   File: JsonSchemaFromFieldDescriptorsGenerator.java    License: MIT License 5 votes vote down vote up
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 Project: json-schema   Author: everit-org   File: SchemaLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: json-schema   Author: everit-org   File: ArraySchemaLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: json-schema   Author: everit-org   File: JSONPrinterTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: apicurio-registry   Author: Apicurio   File: NullSchemaDiffVisitor.java    License: Apache License 2.0 4 votes vote down vote up
public NullSchemaDiffVisitor(DiffContext ctx, NullSchema original) {
    this.ctx = ctx;
    this.original = original;
}
 
Example #9
Source Project: apicurio-registry   Author: Apicurio   File: NullSchemaWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public NullSchemaWrapper(NullSchema wrapped) {
    this.wrapped = wrapped;
}
 
Example #10
Source Project: json-schema   Author: everit-org   File: SchemaLoaderTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void nullSchema() {
    NullSchema actual = (NullSchema) SchemaLoader.load(get("nullSchema"));
    assertNotNull(actual);
}