Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: trunk/src/chrome/renderer/resources/extensions/json_schema.js

Issue 47403003: Revert 231982 "Docserver: Display enum value descriptions in API..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // ----------------------------------------------------------------------------- 5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to 6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect. 7 // have your change take effect.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 9
10 //============================================================================== 10 //==============================================================================
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 if (instance.constructor.name == className) 46 if (instance.constructor.name == className)
47 return true; 47 return true;
48 } 48 }
49 return false; 49 return false;
50 } 50 }
51 51
52 function isOptionalValue(value) { 52 function isOptionalValue(value) {
53 return typeof(value) === 'undefined' || value === null; 53 return typeof(value) === 'undefined' || value === null;
54 } 54 }
55 55
56 function enumToString(enumValue) {
57 return enumValue.name || enumValue;
58 }
59
60 /** 56 /**
61 * Validates an instance against a schema and accumulates errors. Usage: 57 * Validates an instance against a schema and accumulates errors. Usage:
62 * 58 *
63 * var validator = new JSONSchemaValidator(); 59 * var validator = new JSONSchemaValidator();
64 * validator.validate(inst, schema); 60 * validator.validate(inst, schema);
65 * if (validator.errors.length == 0) 61 * if (validator.errors.length == 0)
66 * console.log("Valid!"); 62 * console.log("Valid!");
67 * else 63 * else
68 * console.log(validator.errors); 64 * console.log(validator.errors);
69 * 65 *
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 this.addError(path, "invalidChoice"); 310 this.addError(path, "invalidChoice");
315 }; 311 };
316 312
317 /** 313 /**
318 * Validates an instance against a schema with an enum type. Populates the 314 * Validates an instance against a schema with an enum type. Populates the
319 * |errors| property, and returns a boolean indicating whether the instance 315 * |errors| property, and returns a boolean indicating whether the instance
320 * validates. 316 * validates.
321 */ 317 */
322 JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) { 318 JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) {
323 for (var i = 0; i < schema.enum.length; i++) { 319 for (var i = 0; i < schema.enum.length; i++) {
324 if (instance === enumToString(schema.enum[i])) 320 if (instance === schema.enum[i])
325 return true; 321 return true;
326 } 322 }
327 323
328 this.addError(path, "invalidEnum", 324 this.addError(path, "invalidEnum", [schema.enum.join(", ")]);
329 [schema.enum.map(enumToString).join(", ")]);
330 return false; 325 return false;
331 }; 326 };
332 327
333 /** 328 /**
334 * Validates an instance against an object schema and populates the errors 329 * Validates an instance against an object schema and populates the errors
335 * property. 330 * property.
336 */ 331 */
337 JSONSchemaValidator.prototype.validateObject = 332 JSONSchemaValidator.prototype.validateObject =
338 function(instance, schema, path) { 333 function(instance, schema, path) {
339 if (schema.properties) { 334 if (schema.properties) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 }; 507 };
513 508
514 /** 509 /**
515 * Resets errors to an empty list so you can call 'validate' again. 510 * Resets errors to an empty list so you can call 'validate' again.
516 */ 511 */
517 JSONSchemaValidator.prototype.resetErrors = function() { 512 JSONSchemaValidator.prototype.resetErrors = function() {
518 this.errors = []; 513 this.errors = [];
519 }; 514 };
520 515
521 exports.JSONSchemaValidator = JSONSchemaValidator; 516 exports.JSONSchemaValidator = JSONSchemaValidator;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698