Package com.bazaarvoice.commons.data.model.json.schema

Examples of com.bazaarvoice.commons.data.model.json.schema.JSONSchema


    /**
     * Assumes the array isn't a tuple and returns the schema for the items allowed in this array.
     */
    public JSONSchema getItem() {
        if (_items.isEmpty()) {
            return new JSONSchema();
        }

        return _items.get(0);
    }
View Full Code Here


        setAdditionalItemsSchema(additionalItemsSchema);
        return this;
    }

    public JSONSchemaArrayType allowAdditionalItems() {
        setAdditionalItemsSchema(new JSONSchema());
        return this;
    }
View Full Code Here

            Iterator<JSONSchema> tupleIter = _items.iterator();
            Iterator collIter = coll.iterator();
            int index = 0;
            while (tupleIter.hasNext() && collIter.hasNext()) {
                JSONSchema tupleSchema = tupleIter.next();
                Object tupleObj = collIter.next();
                hasDuplicates = hasDuplicates || !set.add(tupleObj);
                tupleSchema.validate(tupleObj, path + "[" + index + "]", results);

                index++;
            }

            if (_additionalItemsSchema != null) {
                while (collIter.hasNext()) {
                    Object additionalObj = collIter.next();
                    hasDuplicates = hasDuplicates || !set.add(additionalObj);
                    _additionalItemsSchema.validate(additionalObj, path + "[" + index + "]", results);

                    index++;
                }
            } else if (collIter.hasNext()) {
                results.addResult(new ValidationResult().type(ResultType.CONSTRAINT_VIOLATION).path(path).message("Tuple does not allow additional items: " + coll));
            }
        } else {
            int index = 0;
            JSONSchema itemSchema = getItem();
            for (final Object collObj : coll) {
                hasDuplicates = hasDuplicates || !set.add(collObj);
                itemSchema.validate(collObj, path + "[" + index + "]", results);

                index++;
            }
        }
View Full Code Here

        if (!objectType.getPatternProperties().isEmpty()) {
            jsonObject.put("patternProperties", _patternPropertyMarshaller.toMappedJSONObject(objectType.getPatternProperties()));
        }

        JSONSchema additionalPropertiesSchema = objectType.getAdditionalPropertiesSchema();
        if (additionalPropertiesSchema == null) {
            jsonObject.put("additionalProperties", false);
        } else if (!additionalPropertiesSchema.isEmpty()) {
            jsonObject.put("additionalProperties", toJSONObject(additionalPropertiesSchema, false));
        }
    }
View Full Code Here

    protected JSONObject convertArrayTypeFieldsToJSONObject(JSONSchemaArrayType arrayType, JSONObject jsonObject) {
        if (arrayType.isTuple()) {
            jsonObject.put("items", toJSONArray(arrayType.getItems(), false));

            JSONSchema additionalItemsSchema = arrayType.getAdditionalItemsSchema();
            if (additionalItemsSchema == null) {
                jsonObject.put("additionalItems", false);
            } else if (!additionalItemsSchema.isEmpty()) {
                jsonObject.put("additionalItems", toJSONObject(additionalItemsSchema, false));
            }
        } else {
            jsonObject.put("items", toJSONObject(arrayType.getItem(), false));
        }
View Full Code Here

            throws JSONException {
        if (!isSupportedSchema(jsonObject.optString(JSONSchema.SCHEMA_KEY, getSchemaVersion()))) {
            throw new IllegalArgumentException("Unrecognized schema version: " + jsonObject.optString(JSONSchema.SCHEMA_KEY));
        }

        JSONSchema jsonSchema = new JSONSchema();
        String id = jsonObject.optString("id", null);
        if (!Strings.isNullOrEmpty(id)) {
            jsonSchema.setID(id);
            _schemaCache.put(id, jsonSchema);
        }

        String referencesSchemaID = jsonObject.optString("$ref", null);
        if (!Strings.isNullOrEmpty(referencesSchemaID)) {
            jsonSchema.setReferencesSchema(fromSchemaID(referencesSchemaID));
        }

        String extendsSchemaID = jsonObject.optString("extends", null);
        if (!Strings.isNullOrEmpty(extendsSchemaID)) {
            jsonSchema.setExtendsSchema(fromSchemaID(extendsSchemaID));
        }

        jsonSchema.setRequired((Boolean) jsonObject.opt("required"));
        jsonSchema.setTitle(jsonObject.optString("title", null));
        jsonSchema.setDescription(jsonObject.optString("description", null));

        convertTypesFromJSONObject(jsonObject, jsonSchema);

        return jsonSchema;
    }
View Full Code Here

            } else if (additionalItems instanceof Boolean && !((Boolean) additionalItems)) {
                arrayType.additionalItemsSchema(null);
            } else if (additionalItems != null && additionalItems != JSONObject.NULL) {
                throw new IllegalArgumentException("Unsupported additional items: " + additionalItems);
            } else {
                arrayType.additionalItemsSchema(new JSONSchema());
            }
        }

        if (!jsonObject.isNull("minItems")) {
            arrayType.setMinimumItems(jsonObject.getInt("minItems"));
View Full Code Here

TOP

Related Classes of com.bazaarvoice.commons.data.model.json.schema.JSONSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.