i need to validate my aws lambda event schema. i used vandium for validation. i have two diffrent cases.
like this
var vandium = require('vandium');
vandium.validation({
name: vandium.types.string().required()
});
exports.handler = vandium(function (event, context, callback) {
console.log('hello: ' + event.name);
callback(null, 'Hello from Lambda');
});
in this case, vandium only validate , if key is present or not. But i need to check if any extra key is present or not.
like this
var vandium = require('vandium');
vandium.validation({
operation: vandium.types.string().required(),
name: vandium.types.string().required(), });
exports.handler = vandium(function (event, context, callback) {
const operation = event.operation;
switch (operation) {
case 'test1':
test1(event);
break;
case 'test2':
test2(event);
break;
default:
callback(new Error("Unrecognized operation=" + operation));
break;
}
function test1(event) {
//console.log('hello: ' + event.name);
callback(null, 'Hello from Lambda');
}
function test2(event) {
//console.log('hello: ' + event.name);
callback(null, 'Hello from Lambda');
}
});
in this case, events for test1 & test2 are diffrent. like this
test1{"name":"hello","id":100 }
test2{"schoolName":"threni","teacher":"abcd" }
have you taken a look at ajv ? like in Validating Data With JSON-Schema
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With