Skip to content

Commit

Permalink
ajv 6.2.6 -> 8.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahec committed Jan 2, 2025
1 parent 774d3f0 commit 6fd42d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/firebaseConfigValidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
});

Expand All @@ -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({});
});

Expand All @@ -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({});
});
});
11 changes: 6 additions & 5 deletions src/firebaseConfigValidate.ts
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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}`;
}
}

0 comments on commit 6fd42d0

Please sign in to comment.