sap-cap-validator-plugin
v0.0.2
Published
SAP CAP plugin to validate incoming API requests.
Downloads
38
Maintainers
Readme
SAP CAP Validator Plugin
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'
};
};