Serverless-offline: implement Request validation

Created on 6 Jul 2019  路  3Comments  路  Source: dherault/serverless-offline

Most helpful comment

Any update on this feature guys?

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stonebraker picture stonebraker  路  3Comments

aldofunes picture aldofunes  路  3Comments

MEGApixel23 picture MEGApixel23  路  4Comments

Ali-Dalal picture Ali-Dalal  路  4Comments

ozbillwang picture ozbillwang  路  4Comments