Browse Source

Bug fix in validator to deal with adding schemas that are invalid.

Afshin Darian 7 years ago
parent
commit
887e0d097f
1 changed files with 20 additions and 13 deletions
  1. 20 13
      packages/coreutils/src/settingregistry.ts

+ 20 - 13
packages/coreutils/src/settingregistry.ts

@@ -325,21 +325,28 @@ class DefaultSchemaValidator implements ISchemaValidator {
    * It is safe to call this function multiple times with the same plugin name.
    */
   addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null {
-    const validate = this._validator.getSchema('main');
-    const valid = validate(schema);
-
-    if (valid) {
-      // Remove if schema already exists.
-      this._composer.removeSchema(plugin);
-      this._validator.removeSchema(plugin);
-
-      // Add schema to the validator and composer.
-      this._composer.addSchema(schema, plugin);
-      this._validator.addSchema(schema, plugin);
-      return null;
+    const composer = this._composer;
+    const validator = this._validator;
+    const validate = validator.getSchema('main');
+
+    if (!(validate(schema) as boolean)) {
+      return validate.errors as ISchemaValidator.IError[];
+    }
+
+    if (!(validator.validateSchema(schema) as boolean)) {
+      return validator.errors as ISchemaValidator.IError[];
     }
 
-    return validate.errors as ISchemaValidator.IError[];
+    // Remove if schema already exists.
+    composer.removeSchema(plugin);
+    validator.removeSchema(plugin);
+
+    // Add schema to the validator and composer.
+    composer.addSchema(schema, plugin);
+    validator.addSchema(schema, plugin);
+
+    return null;
+
   }
 
   /**