Skip to content

Commit

Permalink
Adding ajv-formats package Vincit#2142, Vincit#2146, Vincit#2147, Vin…
Browse files Browse the repository at this point in the history
  • Loading branch information
TigerC10 committed Feb 6, 2022
1 parent 6ab6dd8 commit 728500f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
11 changes: 11 additions & 0 deletions lib/model/AjvValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const getAjv = once(() => {
}
});

const getAjvFormats = once(() => {
try {
return require('ajv-formats');
} catch (err) {
throw new Error('Optional ajv-formats dependency not installed. Please run `npm install ajv-formats --save`');
}
});

class AjvValidator extends Validator {
static init(self, conf) {
super.init(self, conf);
Expand All @@ -21,6 +29,7 @@ class AjvValidator extends Validator {
});

const Ajv = getAjv();
const addFormats = getAjvFormats();

// Create a normal Ajv instance.
self.ajv = new Ajv(
Expand All @@ -32,6 +41,8 @@ class AjvValidator extends Validator {
)
);

addFormats(self.ajv);

// Create an instance that doesn't set default values. We need this one
// to validate `patch` objects (objects that have a subset of properties).
self.ajvNoDefaults = new Ajv(
Expand Down
45 changes: 36 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
],
"types": "./typings/objection/index.d.ts",
"dependencies": {
"ajv": "^8.6.2",
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"db-errors": "^0.2.3"
},
"peerDependencies": {
Expand Down

0 comments on commit 728500f

Please sign in to comment.