| Index: chrome/renderer/resources/extensions/json_schema.js
|
| diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js
|
| index ad47748ae0c5bd90f3becc5baefb23e8e9946df5..717ef50c3f4abce064c590bcb08cec515b0b32c1 100644
|
| --- a/chrome/renderer/resources/extensions/json_schema.js
|
| +++ b/chrome/renderer/resources/extensions/json_schema.js
|
| @@ -144,6 +144,52 @@ chromeHidden.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) {
|
| }
|
|
|
| /**
|
| + * Returns a list of strings of the types that this schema accepts.
|
| + */
|
| +chromeHidden.JSONSchemaValidator.prototype.getAllTypesForSchema = function(
|
| + schema) {
|
| + var schemaTypes = [];
|
| + if (schema.type)
|
| + schemaTypes.push(schema.type);
|
| + if (schema.choices) {
|
| + for (var i = 0; i < schema.choices.length; i++)
|
| + schemaTypes.push(schema.choices[i].type);
|
| + }
|
| + if (schema['$ref']) {
|
| + var refTypes = this.getAllTypesForSchema(this.types[schema['$ref']]);
|
| + schemaTypes = schemaTypes.concat(refTypes);
|
| + }
|
| + return schemaTypes;
|
| +};
|
| +
|
| +/**
|
| + * Returns true if |schema| would accept an argument of type |type|.
|
| + */
|
| +chromeHidden.JSONSchemaValidator.prototype.isValidSchemaType = function(
|
| + type, schema) {
|
| + schemaTypes = this.getAllTypesForSchema(schema);
|
| + for (var i = 0; i < schemaTypes.length; i++) {
|
| + if (schemaTypes[i] == "any" || type == schemaTypes[i])
|
| + return true;
|
| + }
|
| + return type == "any";
|
| +};
|
| +
|
| +/**
|
| + * Returns true if there is a non-null argument that both |schema1| and
|
| + * |schema2| would accept.
|
| + */
|
| +chromeHidden.JSONSchemaValidator.prototype.checkSchemaOverlap = function(
|
| + schema1, schema2) {
|
| + var schema1Types = this.getAllTypesForSchema(schema1);
|
| + for (var i = 0; i < schema1Types.length; i++) {
|
| + if (this.isValidSchemaType(schema1Types[i], schema2))
|
| + return true;
|
| + }
|
| + return false;
|
| +};
|
| +
|
| +/**
|
| * Validates an instance against a schema. The instance can be any JavaScript
|
| * value and will be validated recursively. When this method returns, the
|
| * |errors| property will contain a list of errors, if any.
|
| @@ -448,4 +494,11 @@ chromeHidden.JSONSchemaValidator.prototype.addError = function(
|
| });
|
| };
|
|
|
| +/**
|
| + * Resets errors to an empty list so you can call 'validate' again.
|
| + */
|
| +chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() {
|
| + this.errors = [];
|
| +};
|
| +
|
| })();
|
|
|