diff --git a/package.json b/package.json index b25f40497f9c..2faa3a5cee04 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "@google-cloud/cloud-sql-connector": "^1.3.3", "@google-cloud/pubsub": "^4.5.0", "abort-controller": "^3.0.0", - "ajv": "^6.12.6", + "ajv": "^8.17.1", "archiver": "^7.0.0", "async-lock": "1.4.1", "body-parser": "^1.19.0", diff --git a/src/firebaseConfigValidate.spec.ts b/src/firebaseConfigValidate.spec.ts index a1191d7eeed3..327011a577bb 100644 --- a/src/firebaseConfigValidate.spec.ts +++ b/src/firebaseConfigValidate.spec.ts @@ -42,7 +42,7 @@ describe("firebaseConfigValidate", () => { const firstError = validator.errors![0]; expect(firstError.keyword).to.eq("additionalProperties"); - expect(firstError.dataPath).to.eq(""); + expect(firstError.instancePath).to.eq(""); expect(firstError.params).to.deep.equal({ additionalProperty: "bananas" }); }); @@ -63,18 +63,18 @@ describe("firebaseConfigValidate", () => { // Missing required param expect(firstError.keyword).to.eq("required"); - expect(firstError.dataPath).to.eq(".storage"); + expect(firstError.instancePath).to.eq("/storage"); expect(firstError.params).to.deep.equal({ missingProperty: "rules" }); // Because it doesn't match the object type, we also get an "is not an array" // error since JSON Schema can't tell which type it is closest to. expect(secondError.keyword).to.eq("type"); - expect(secondError.dataPath).to.eq(".storage"); + expect(secondError.instancePath).to.eq("/storage"); expect(secondError.params).to.deep.equal({ type: "array" }); // Finally we get an error saying that 'storage' is not any of the known types expect(thirdError.keyword).to.eq("anyOf"); - expect(thirdError.dataPath).to.eq(".storage"); + expect(thirdError.instancePath).to.eq("/storage"); expect(thirdError.params).to.deep.equal({}); }); @@ -97,18 +97,18 @@ describe("firebaseConfigValidate", () => { // Wrong type expect(firstError.keyword).to.eq("type"); - expect(firstError.dataPath).to.eq(".storage.rules"); + expect(firstError.instancePath).to.eq("/storage/rules"); expect(firstError.params).to.deep.equal({ type: "string" }); // Because it doesn't match the object type, we also get an "is not an array" // error since JSON Schema can't tell which type it is closest to. expect(secondError.keyword).to.eq("type"); - expect(secondError.dataPath).to.eq(".storage"); + expect(secondError.instancePath).to.eq("/storage"); expect(secondError.params).to.deep.equal({ type: "array" }); // Finally we get an error saying that 'storage' is not any of the known types expect(thirdError.keyword).to.eq("anyOf"); - expect(thirdError.dataPath).to.eq(".storage"); + expect(thirdError.instancePath).to.eq("/storage"); expect(thirdError.params).to.deep.equal({}); }); }); diff --git a/src/firebaseConfigValidate.ts b/src/firebaseConfigValidate.ts index 4a6a7413413b..f662a6d6e663 100644 --- a/src/firebaseConfigValidate.ts +++ b/src/firebaseConfigValidate.ts @@ -1,12 +1,13 @@ -// Note: we are using ajv version 6.x because it's compatible with TypeScript -// 3.x, if we upgrade the TS version in this project we can upgrade ajv as well. +// Note: Upgraded ajv from 6 to 8 as we upgraded from Typescript 3 import { ValidateFunction, ErrorObject } from "ajv"; import * as fs from "fs"; import * as path from "path"; const Ajv = require("ajv"); +const addFormats = require("ajv-formats"); const ajv = new Ajv(); +addFormats(ajv); let _VALIDATOR: ValidateFunction | undefined = undefined; /** @@ -30,14 +31,14 @@ export function getValidator(): ValidateFunction { export function getErrorMessage(e: ErrorObject) { if (e.keyword === "additionalProperties") { - return `Object "${e.dataPath}" in "firebase.json" has unknown property: ${JSON.stringify( + return `Object "${e.instancePath}" in "firebase.json" has unknown property: ${JSON.stringify( e.params, )}`; } else if (e.keyword === "required") { return `Object "${ - e.dataPath + e.instancePath }" in "firebase.json" is missing required property: ${JSON.stringify(e.params)}`; } else { - return `Field "${e.dataPath}" in "firebase.json" is possibly invalid: ${e.message}`; + return `Field "${e.instancePath}" in "firebase.json" is possibly invalid: ${e.message}`; } }