sap-cap-validator-plugin

0.0.2 • Public • Published

SAP CAP Validator Plugin

npm test

A SAP CAP plugin to validate incoming data.

This plugin uses Ajv, a JSON schema validator. All validation keywords available in Ajv (draft-07) can be used.

Setup

All you need to do is to install the plugin and add the @Validator annotations to your entities.

Installation

Install the plugin as an npm module:

npm install sap-cap-validator-plugin

Annotation

The annotation tag is @Validator. You can add and combine valid rules from JSON Schema such as types and formats

using {myService as service} from './services';

annotate service.myEntity with {
  field_duration            @Validator: {format: 'duration'};
  field_uri                 @Validator: {format: 'uri'};
  field_url                 @Validator: {format: 'url'};
  field_email               @Validator: {format: 'email'};
  field_hostname            @Validator: {format: 'hostname'};
  field_ipv4                @Validator: {format: 'ipv4'};
  field_ipv6                @Validator: {format: 'ipv6'};
  field_datetime            @Validator: {
    type: 'string',
    format: 'date-time'
  };
};

Package Sidebar

Install

npm i sap-cap-validator-plugin

Weekly Downloads

8

Version

0.0.2

License

MIT

Unpacked Size

42.2 kB

Total Files

32

Last publish

Collaborators

  • mauriciolauffer