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.
All you need to do is to install the plugin and add the @Validator
annotations to your entities.
Install the plugin as an npm module:
npm install sap-cap-validator-plugin
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'
};
};