serverless: https://github.com/serverless/serverless/pull/5956
https://serverless.com/framework/docs/providers/aws/events/apigateway/#request-schema-validation
former PR, could maybe re-use tests: https://github.com/dherault/serverless-offline/pull/589
Dears, other day I implemented a poc using Ajv for an API middleware. I'll try to work on that this weekend.
It is something like this:
const Ajv = require('ajv');
const ajv = new Ajv({$data: true});
// Actually, load all scheme first and put them in a object.
// schemeFile = loaded from yml:function:events:http:requests:schema:
const testSchema = ajv.compile(schemeFile);
Validation could be something like this:
// Content-Type: application/json
const parsedBody = JSON.parse(event.body)
const valid = testSchema(parsedBody);
if (valid){
// call function
}else {
return {
statusCode: 422,
body: JSON.stringify(errorTemplate)
};}
Any update on this feature guys?
Bump
Most helpful comment
Any update on this feature guys?