Skip to content

Commit

Permalink
Add base for validation
Browse files Browse the repository at this point in the history
* Referencing #25
  • Loading branch information
vjspranav committed Jun 4, 2021
1 parent e1f4ad0 commit 9ad3993
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"scripts": {
"labgen": "node main.js",
"validate-lab-descriptor": "node validateDescriptor.js",
"validate-schema": "node validation/validate.js",
"build-ds-exp": "node exp.js --env=testing ../",
"build-exp": "node exp.js --env=testing ../"
},
Expand Down
4 changes: 4 additions & 0 deletions validation/schemaMap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"posttest.json": "./schemas/quizv2Schema.json",
"pretest.json" : "./schemas/quizv2Schema.json"
}
43 changes: 43 additions & 0 deletions validation/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const Ajv = require('ajv');
const path = require('path');
const schemaMap = require('./schemaMap.json')

let validateSchema = (input="1", schema="1") => {
console.log("validating " + input + " against " + schema);
console.log("You got validated");
}

module.exports.validateSchema = validateSchema;

/**
* node validation/validate.js <jsonpath> <schema path>
*/
if (require.main === module) {
let json=""
let schema=""
console.log(process.argv.length)
switch(process.argv.length){
case 2:
console.log('validating all')
validateSchema();
break;
case 3:
json = process.argv[2];
json = json.replace('/', '\\')
let n = json.lastIndexOf('\\');
let jsonKey = json.substring(n + 1);
console.log(json, n)
schema=schemaMap[jsonKey];
console.log(schema)
validateSchema(json, schema);
break
case 4:
json = path.resolve(process.argv[2]);
schema=path.resolve(process.argv[3]);
validateSchema(json, schema);
break
default:
console.log("Error")
}
}

0 comments on commit 9ad3993

Please sign in to comment.