Unverified Commit 763bf21b authored by Károly Erdős's avatar Károly Erdős Committed by GitHub
Browse files

Merge pull request #5 from elixir-europe/update_to_latest_ajv

Update AJV library to the latest stable version (7.2.1)
parents 139ffd0c 9910cee2
This diff is collapsed.
......@@ -22,7 +22,8 @@
"author": "EMBL-EBI-SUBS, fpenim, ke4, haseeb-gh",
"license": "Apache-2.0",
"dependencies": {
"ajv": "^6.10.2",
"ajv": "~7.2.1",
"ajv-formats": "^1.5.1",
"express": "^4.17.1",
"npid": "^0.4.0",
"request": "^2.88.2",
......
......@@ -5,7 +5,8 @@
const Promise = require('bluebird');
const path = require("path");
const fs = require('fs');
const ajv = require("ajv");
const Ajv = require("ajv").default;
const addFormats = require("ajv-formats");
const request = require("request-promise");
const AppError = require("./model/application-error");
......@@ -39,7 +40,7 @@ class BioValidator {
}
}
).catch((err) => {
if (!(err instanceof ajv.ValidationError)) {
if (!(err instanceof Ajv.ValidationError)) {
console.error("An error occurred while running the validation.");
reject(new AppError("An error occurred while running the validation."));
} else {
......@@ -100,8 +101,8 @@ class BioValidator {
}
constructAjv(customKeywordValidators) {
const ajvInstance = new ajv({allErrors: true, schemaId: 'id', loadSchema: this.generateLoadSchemaRefFn()});
ajvInstance.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
const ajvInstance = new Ajv({allErrors: true, strict:false, loadSchema: this.generateLoadSchemaRefFn()});
addFormats(ajvInstance);
BioValidator._addCustomKeywordValidators(ajvInstance, customKeywordValidators);
return ajvInstance
......
const CurieExpansion = require("../utils/curie_expansion");
const ajv = require("ajv");
const ajv = require("ajv").default;
const request = require("request-promise");
const CustomAjvError = require("../model/custom-ajv-error");
......@@ -17,13 +17,14 @@ class GraphRestriction {
*/
configure(ajv) {
const keywordDefinition= {
keyword: this.keywordName,
async: GraphRestriction._isAsync(),
type: "string",
validate: this.generateKeywordFunction(),
errors: true
};
return ajv.addKeyword(this.keywordName, keywordDefinition);
return ajv.addKeyword(keywordDefinition);
}
keywordFunction() {
......
const Ajv = require("ajv");
const Ajv = require("ajv").default;
const request = require("request");
const logger = require("../winston");
const CustomAjvError = require("../model/custom-ajv-error");
......@@ -11,13 +11,14 @@ class IsChildTermOf {
configure(ajv) {
const keywordDefinition= {
keyword: this.keywordName,
async: this.isAsync(),
type: "string",
validate: this.generateKeywordFunction(),
errors: true
};
return ajv.addKeyword(this.keywordName, keywordDefinition);
return ajv.addKeyword( keywordDefinition);
}
keywordFunction() {
......
const Ajv = require("ajv");
const Ajv = require("ajv").default;
const request = require("request");
const logger = require("../winston");
const CustomAjvError = require("../model/custom-ajv-error");
......@@ -13,13 +13,14 @@ class IsValidTaxonomy {
configure(ajv) {
const keywordDefinition = {
keyword: this.keywordName,
async: this.isAsync(),
type: "string",
validate: this.generateKeywordFunction(),
errors: true
};
return ajv.addKeyword(this.keywordName, keywordDefinition);
return ajv.addKeyword(keywordDefinition);
}
keywordFunction() {
......
const Ajv = require("ajv");
const Ajv = require("ajv").default;
const request = require("request");
const logger = require("../winston");
const CustomAjvError = require("../model/custom-ajv-error");
......@@ -11,13 +11,14 @@ class IsValidTerm {
configure(ajv) {
const keywordDefinition = {
keyword: this.keywordName,
async: this.isAsync(),
type: "string",
validate: this.generateKeywordFunction(),
errors: true
};
return ajv.addKeyword(this.keywordName, keywordDefinition);
return ajv.addKeyword(keywordDefinition);
}
keywordFunction() {
......@@ -72,4 +73,4 @@ class IsValidTerm {
}
}
module.exports = IsValidTerm;
\ No newline at end of file
module.exports = IsValidTerm;
......@@ -2,24 +2,24 @@ const fs = require("fs");
const runValidation = require("../src/validator");
test(" -> isChildTermOf Schema", () => {
let inputSchema = fs.readFileSync("examples/schemas/isChildTerm-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/isChildTerm-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/isChildTerm.json");
let inputObj = fs.readFileSync("examples/objects/isChildTerm.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
expect(data).toBeDefined();
expect(data[0]).toBeDefined();
expect(data[0].dataPath).toBe(".attributes['age'][0].terms[0].url");
expect(data[0].dataPath).toBe("/attributes/age/0/terms/0/url");
});
});
test("FAANG Schema - FAANG \'organism\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-organism-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-organism-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -29,10 +29,10 @@ test("FAANG Schema - FAANG \'organism\' sample", () => {
});
test("FAANG Schema - \'specimen\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-specimen-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-specimen-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -42,10 +42,10 @@ test("FAANG Schema - \'specimen\' sample", () => {
});
test("FAANG Schema - \'pool of specimens\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-poolOfSpecimens-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-poolOfSpecimens-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -55,10 +55,10 @@ test("FAANG Schema - \'pool of specimens\' sample", () => {
});
test("FAANG Schema - \'cell specimen\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-cellSpecimen-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-cellSpecimen-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -68,10 +68,10 @@ test("FAANG Schema - \'cell specimen\' sample", () => {
});
test("FAANG Schema - \'cell culture\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-cellCulture-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-cellCulture-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -81,10 +81,10 @@ test("FAANG Schema - \'cell culture\' sample", () => {
});
test("FAANG Schema - \'cell line\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/faang-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-cellLine-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-cellLine-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......
......@@ -9,10 +9,10 @@ test("Empty Schema (empty object)", () => {
});
test("Attributes Schema", () => {
let inputSchema = fs.readFileSync("examples/schemas/attributes-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/attributes-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/attributes.json");
let inputObj = fs.readFileSync("examples/objects/attributes.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -24,10 +24,10 @@ test("Attributes Schema", () => {
});
test("BioSamples Schema - FAANG \'organism\' sample", () => {
let inputSchema = fs.readFileSync("examples/schemas/biosamples-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/biosamples-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/faang-organism-sample.json");
let inputObj = fs.readFileSync("examples/objects/faang-organism-sample.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
......@@ -37,14 +37,14 @@ test("BioSamples Schema - FAANG \'organism\' sample", () => {
});
test("Study Schema", () => {
let inputSchema = fs.readFileSync("examples/schemas/submittables/study-schema.json");
let inputSchema = fs.readFileSync("examples/schemas/submittables/study-schema.json", "utf-8");
let jsonSchema = JSON.parse(inputSchema);
let inputObj = fs.readFileSync("examples/objects/study.json");
let inputObj = fs.readFileSync("examples/objects/study.json", "utf-8");
let jsonObj = JSON.parse(inputObj);
return runValidation(jsonSchema, jsonObj).then( (data) => {
expect(data).toBeDefined();
expect(data.length).toBe(2);
});
});
\ No newline at end of file
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment