Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

serverless-reqvalidator-plugin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-reqvalidator-plugin - npm Package Compare versions

Comparing version
2.0.0
to
3.0.0
+11
test/fixtures/externalValidatorFunction.yaml
plugins:
- serverless-reqvalidator-plugin
service: my-service-b
functions:
hello:
handler: handler.myHandler
events:
- http:
path: hello
reqValidatorName:
Fn::ImportValue: 'myReqValidator'
plugins:
- serverless-reqvalidator-plugin
service: my-service-d
functions:
hello:
handler: handler.myHandler
events:
- http:
path: hello
reqValidatorName:
data: 123
plugins:
- serverless-reqvalidator-plugin
service: my-service-a
functions:
hello:
handler: handler.myHandler
events:
- http:
path: hello
reqValidatorName: 'myReqValidator'
resources:
Resources:
xMyRequestValidator:
Type: "AWS::ApiGateway::RequestValidator"
Properties:
Name: 'my-req-validator'
RestApiId:
Ref: ApiGatewayRestApi
ValidateRequestBody: true
ValidateRequestParameters: false
Outputs:
xMyRequestValidator:
Value:
Ref: my-req-validator
Export:
Name: myReqValidator
plugins:
- serverless-reqvalidator-plugin
service: my-service-c
functions:
hello:
handler: handler.myHandler
events:
- http:
path: hello
const Ajv = require('ajv');
const yaml = require('js-yaml');
const fs = require('fs');
const { ServerlessReqValidatorPluginConfigSchema } = require('../src/index');
const ajv = new Ajv();
const validateConfig = ajv.compile({
type: 'object',
...ServerlessReqValidatorPluginConfigSchema,
});
describe('serverless-reqvalidator-plugin schema', () => {
it('should validate a configuration without reqValidatorName property', () => {
const config = yaml.load(fs.readFileSync('./test/fixtures/noValidatorFunction.yaml', 'utf8'));
const valid = validateConfig(config.functions.hello.events[0].http);
expect(valid).toBeTruthy();
});
it('should validate a configuration with a local reqValidatorName property', () => {
const config = yaml.load(fs.readFileSync('./test/fixtures/localValidatorFunction.yaml', 'utf8'));
const valid = validateConfig(config.functions.hello.events[0].http);
expect(valid).toBeTruthy();
});
it('should validate a configuration with an external reqValidatorName property', () => {
const config = yaml.load(fs.readFileSync('./test/fixtures/externalValidatorFunction.yaml', 'utf8'));
const valid = validateConfig(config.functions.hello.events[0].http);
expect(valid).toBeTruthy();
});
it('should not validate a configuration with an invalid reqValidatorName property', () => {
const config = yaml.load(fs.readFileSync('./test/fixtures/invalidValidatorFunction.yaml', 'utf8'));
const valid = validateConfig(config.functions.hello.events[0].http);
expect(valid).toBeFalsy();
});
});
+8
-3
{
"name": "serverless-reqvalidator-plugin",
"version": "2.0.0",
"version": "3.0.0",
"description": "Serverless plugin for setting request validation",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest test"
},

@@ -26,3 +26,8 @@ "repository": {

},
"homepage": "https://github.com/RafPe/serverless-reqvalidator-plugin#readme"
"homepage": "https://github.com/RafPe/serverless-reqvalidator-plugin#readme",
"devDependencies": {
"ajv": "^8.11.2",
"jest": "^29.3.1",
"js-yaml": "^4.1.0"
}
}

@@ -36,2 +36,17 @@ 'use strict';

const ServerlessReqValidatorPluginConfigSchema = {
properties: {
reqValidatorName: {
anyOf: [
{ type: 'string' },
{ type: 'object',
properties: {
'Fn::ImportValue': { type: 'string' }
},
required: ['Fn::ImportValue'],
},
]
},
},
}
class ServerlessReqValidatorPlugin {

@@ -51,7 +66,3 @@ constructor(serverless, options) {

// Create schema for your properties. For reference use https://github.com/ajv-validator/ajv
serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', {
properties: {
reqValidatorName: { type: 'string' },
},
});
serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', ServerlessReqValidatorPluginConfigSchema);

@@ -118,1 +129,2 @@ this.hooks = {

module.exports = ServerlessReqValidatorPlugin;
module.exports.ServerlessReqValidatorPluginConfigSchema = ServerlessReqValidatorPluginConfigSchema;