Skip to content

Commit 6fd42d0

Browse files
committed
ajv 6.2.6 -> 8.1.1
1 parent 774d3f0 commit 6fd42d0

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"@google-cloud/cloud-sql-connector": "^1.3.3",
104104
"@google-cloud/pubsub": "^4.5.0",
105105
"abort-controller": "^3.0.0",
106-
"ajv": "^6.12.6",
106+
"ajv": "^8.17.1",
107107
"archiver": "^7.0.0",
108108
"async-lock": "1.4.1",
109109
"body-parser": "^1.19.0",

src/firebaseConfigValidate.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("firebaseConfigValidate", () => {
4242

4343
const firstError = validator.errors![0];
4444
expect(firstError.keyword).to.eq("additionalProperties");
45-
expect(firstError.dataPath).to.eq("");
45+
expect(firstError.instancePath).to.eq("");
4646
expect(firstError.params).to.deep.equal({ additionalProperty: "bananas" });
4747
});
4848

@@ -63,18 +63,18 @@ describe("firebaseConfigValidate", () => {
6363

6464
// Missing required param
6565
expect(firstError.keyword).to.eq("required");
66-
expect(firstError.dataPath).to.eq(".storage");
66+
expect(firstError.instancePath).to.eq("/storage");
6767
expect(firstError.params).to.deep.equal({ missingProperty: "rules" });
6868

6969
// Because it doesn't match the object type, we also get an "is not an array"
7070
// error since JSON Schema can't tell which type it is closest to.
7171
expect(secondError.keyword).to.eq("type");
72-
expect(secondError.dataPath).to.eq(".storage");
72+
expect(secondError.instancePath).to.eq("/storage");
7373
expect(secondError.params).to.deep.equal({ type: "array" });
7474

7575
// Finally we get an error saying that 'storage' is not any of the known types
7676
expect(thirdError.keyword).to.eq("anyOf");
77-
expect(thirdError.dataPath).to.eq(".storage");
77+
expect(thirdError.instancePath).to.eq("/storage");
7878
expect(thirdError.params).to.deep.equal({});
7979
});
8080

@@ -97,18 +97,18 @@ describe("firebaseConfigValidate", () => {
9797

9898
// Wrong type
9999
expect(firstError.keyword).to.eq("type");
100-
expect(firstError.dataPath).to.eq(".storage.rules");
100+
expect(firstError.instancePath).to.eq("/storage/rules");
101101
expect(firstError.params).to.deep.equal({ type: "string" });
102102

103103
// Because it doesn't match the object type, we also get an "is not an array"
104104
// error since JSON Schema can't tell which type it is closest to.
105105
expect(secondError.keyword).to.eq("type");
106-
expect(secondError.dataPath).to.eq(".storage");
106+
expect(secondError.instancePath).to.eq("/storage");
107107
expect(secondError.params).to.deep.equal({ type: "array" });
108108

109109
// Finally we get an error saying that 'storage' is not any of the known types
110110
expect(thirdError.keyword).to.eq("anyOf");
111-
expect(thirdError.dataPath).to.eq(".storage");
111+
expect(thirdError.instancePath).to.eq("/storage");
112112
expect(thirdError.params).to.deep.equal({});
113113
});
114114
});

src/firebaseConfigValidate.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// Note: we are using ajv version 6.x because it's compatible with TypeScript
2-
// 3.x, if we upgrade the TS version in this project we can upgrade ajv as well.
1+
// Note: Upgraded ajv from 6 to 8 as we upgraded from Typescript 3
32
import { ValidateFunction, ErrorObject } from "ajv";
43
import * as fs from "fs";
54
import * as path from "path";
65

76
const Ajv = require("ajv");
7+
const addFormats = require("ajv-formats");
88

99
const ajv = new Ajv();
10+
addFormats(ajv);
1011
let _VALIDATOR: ValidateFunction | undefined = undefined;
1112

1213
/**
@@ -30,14 +31,14 @@ export function getValidator(): ValidateFunction {
3031

3132
export function getErrorMessage(e: ErrorObject) {
3233
if (e.keyword === "additionalProperties") {
33-
return `Object "${e.dataPath}" in "firebase.json" has unknown property: ${JSON.stringify(
34+
return `Object "${e.instancePath}" in "firebase.json" has unknown property: ${JSON.stringify(
3435
e.params,
3536
)}`;
3637
} else if (e.keyword === "required") {
3738
return `Object "${
38-
e.dataPath
39+
e.instancePath
3940
}" in "firebase.json" is missing required property: ${JSON.stringify(e.params)}`;
4041
} else {
41-
return `Field "${e.dataPath}" in "firebase.json" is possibly invalid: ${e.message}`;
42+
return `Field "${e.instancePath}" in "firebase.json" is possibly invalid: ${e.message}`;
4243
}
4344
}

0 commit comments

Comments
 (0)