How to use json-schema - 10 common examples

To help you get started, we’ve selected a few json-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / json-schema / json-schema-tests.ts View on Github external
readOnly: false,
        writeOnly: false,
        contentEncoding: 'base64',
        contentMediaType: 'text',
        else: {},
        if: {},
        then: {}
    }
    const c: JSONSchema7Definition = false;
}

// Class
class Schema7 implements JSONSchema7 {
}

let result = validate({}, { $id: 'schema-id' });
mustBeValid(result);

result = checkPropertyChange({ foo: 'bar' }, { $id: 'schema-id' }, 'foo');
github DefinitelyTyped / DefinitelyTyped / types / json-schema / json-schema-tests.ts View on Github external
writeOnly: false,
        contentEncoding: 'base64',
        contentMediaType: 'text',
        else: {},
        if: {},
        then: {}
    }
    const c: JSONSchema7Definition = false;
}

// Class
class Schema7 implements JSONSchema7 {
}

let result = validate({}, { $id: 'schema-id' });
mustBeValid(result);

result = checkPropertyChange({ foo: 'bar' }, { $id: 'schema-id' }, 'foo');
github DefinitelyTyped / DefinitelyTyped / types / json-schema / json-schema-tests.ts View on Github external
contentMediaType: 'text',
        else: {},
        if: {},
        then: {}
    }
    const c: JSONSchema7Definition = false;
}

// Class
class Schema7 implements JSONSchema7 {
}

let result = validate({}, { $id: 'schema-id' });
mustBeValid(result);

result = checkPropertyChange({ foo: 'bar' }, { $id: 'schema-id' }, 'foo');
github splunk / splunk-aws-project-trumpet / cloudtrail-serverless / lambda_code / cloudtrail_logger / node_modules / jsprim / lib / jsprim.js View on Github external
function validateJsonObjectJS(schema, input)
{
	var report = mod_jsonschema.validate(input, schema);

	if (report.errors.length === 0)
		return (null);

	/* Currently, we only do anything useful with the first error. */
	var error = report.errors[0];

	/* The failed property is given by a URI with an irrelevant prefix. */
	var propname = error['property'];
	var reason = error['message'].toLowerCase();
	var i, j;

	/*
	 * There's at least one case where the property error message is
	 * confusing at best.  We work around this here.
	 */
github joyent / node-jsprim / lib / jsprim.js View on Github external
function validateJsonObjectJS(schema, input)
{
	var report = mod_jsonschema.validate(input, schema);

	if (report.errors.length === 0)
		return (null);

	/* Currently, we only do anything useful with the first error. */
	var error = report.errors[0];

	/* The failed property is given by a URI with an irrelevant prefix. */
	var propname = error['property'];
	var reason = error['message'].toLowerCase();
	var i, j;

	/*
	 * There's at least one case where the property error message is
	 * confusing at best.  We work around this here.
	 */
github persvr / perstore / facet.js View on Github external
value: function(directives){
								var i, id;

								directives = directives || {};
								if(this != source){
									directives.previous = copy(source, {});
								}
								if(facetPrototype.save){
									facetPrototype.save.call(this, directives);
								}
								var validation = validate(this, facetSchema);
								var instance = this;
								for(i in this){
									if(this.hasOwnProperty(i)){
										transfer(this[i]);
									}
								}
								for (i in source){
									if(source.hasOwnProperty(i) && !this.hasOwnProperty(i)){
										transfer(undefined);
									}
								}
								mustBeValid(validation);
								var isNew = partial === NEW;
								if(isNew && (typeof facetSchema.add === "function")){ //  || )
									partial = undefined;
									id = facetSchema.add(source, directives);
github persvr / perstore / store / inherited.js View on Github external
/**
 * This store wrapper provides a means for creating a set of stores (from a single store)
 * that can inherit from each other with a superset/subset relation. One can use
 * schemas to indicate the hierarchy (with the "extends" property), and a property
 * is added to the instances to indicate what schema/model each instance belongs to.
 * See tests/inherited.js for an example.   
 */
var getLink = require("json-schema/lib/validate").getLink,
	promise = require("promised-io/promise"),
	subSchemas = {};
exports.Inherited = function(store, schemaProperty){
	// TODO: determine the schemaProperty from the schema's "schema" relation
	schemaProperty = schemaProperty || "__schema__";
	var hierarchy = [];
	var id = promise.defer();
	var inheritingStore = {};
	for(var i in store){
		inheritingStore[i] = store[i];
	}
	var schema;
	var originalSetSchema = store.setSchema;
	inheritingStore.setSchema = function(newSchema){
		schema = newSchema;
		originalSetSchema && originalSetSchema.call(store, schema);
github persvr / perstore / facet.js View on Github external
if(facetPrototype.save){
									facetPrototype.save.call(this, directives);
								}
								var validation = validate(this, facetSchema);
								var instance = this;
								for(i in this){
									if(this.hasOwnProperty(i)){
										transfer(this[i]);
									}
								}
								for (i in source){
									if(source.hasOwnProperty(i) && !this.hasOwnProperty(i)){
										transfer(undefined);
									}
								}
								mustBeValid(validation);
								var isNew = partial === NEW;
								if(isNew && (typeof facetSchema.add === "function")){ //  || )
									partial = undefined;
									id = facetSchema.add(source, directives);
								}
								else if(typeof facetSchema.put === "function"){
									if(isNew){
										directives.overwrite = false;
									}
									id = facetSchema.put(source, directives);
								}
								else if(permissive && isNew && typeof sourceClass.add === "function"){
									id = sourceClass.add(source, directives);
								}
								else if(permissive && typeof sourceClass.put === "function"){
									if(isNew){