diff --git a/package.json b/package.json index 110f4c26..e1770998 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "@oclif/core": "^1.15.0", "@parcel/core": "^2.7.0", "@parcel/reporter-cli": "^2.7.0", - "ajv": "^6", + "ajv": "^8", + "ajv-formats": "^2.1.1", "chalk": "^4", "chokidar": "^3.5.2", "debug": "^4.1.1", diff --git a/schema/config.schema.json b/schema/config.schema.json index 1c6d4e71..552c93e8 100644 --- a/schema/config.schema.json +++ b/schema/config.schema.json @@ -102,7 +102,7 @@ }, "ims_org_id": { "type": "string", - "format": "email" + "pattern": "^(\\w+)@(\\w+)" } }, "required": [ "id", "name", "ims_org_id" ] diff --git a/src/lib/import-helper.js b/src/lib/import-helper.js index f43acf4d..01694969 100644 --- a/src/lib/import-helper.js +++ b/src/lib/import-helper.js @@ -18,6 +18,7 @@ const inquirer = require('inquirer') const yaml = require('js-yaml') const hjson = require('hjson') const Ajv = require('ajv') +const ajvAddFormats = require('ajv-formats') const { EOL } = require('os') const AIO_FILE = '.aio' @@ -43,6 +44,7 @@ function validateConfig (configJson) { /* eslint-disable-next-line node/no-unpublished-require */ const schema = require('../../schema/config.schema.json') const ajv = new Ajv({ allErrors: true }) + ajvAddFormats(ajv) const validate = ajv.compile(schema) return { valid: validate(configJson), errors: validate.errors } diff --git a/test/schema.test.js b/test/schema.test.js index b36257c3..c855e96c 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -1,8 +1,10 @@ const Ajv = require('ajv') +const ajvAddFormats = require('ajv-formats') const schema = require('../schema/config.schema.json') test('validate success', () => { const ajv = new Ajv({ allErrors: true }) + ajvAddFormats(ajv) const validate = ajv.compile(schema) const valid = validate(fixtureJson('valid.config.json')) expect(validate.errors).toEqual(null) @@ -11,6 +13,7 @@ test('validate success', () => { test('validate failure', () => { const ajv = new Ajv({ allErrors: true }) + ajvAddFormats(ajv) const validate = ajv.compile(schema) const valid = validate(fixtureJson('invalid.config.json')) // the 4 errors are the missing name properties, techacct migration to two new properties