https://github.com/mauriciolauffer/sap-cap-validator-plugin
SAP CAP plugin to validate incoming API requests.
https://github.com/mauriciolauffer/sap-cap-validator-plugin
cap cap-js cds cds-plugin nodejs plugin sap sap-cap validation validator
Last synced: 12 months ago
JSON representation
SAP CAP plugin to validate incoming API requests.
- Host: GitHub
- URL: https://github.com/mauriciolauffer/sap-cap-validator-plugin
- Owner: mauriciolauffer
- License: mit
- Created: 2024-01-08T02:06:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-01T02:52:36.000Z (about 2 years ago)
- Last Synced: 2025-05-29T20:16:14.678Z (about 1 year ago)
- Topics: cap, cap-js, cds, cds-plugin, nodejs, plugin, sap, sap-cap, validation, validator
- Language: TypeScript
- Homepage:
- Size: 359 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# SAP CAP Validator Plugin
[](https://www.npmjs.com/package/sap-cap-validator-plugin) [](https://github.com/mauriciolauffer/sap-cap-validator-plugin/actions/workflows/test.yml)
A [SAP CAP plugin](https://cap.cloud.sap/docs/node.js/cds-plugins) to validate incoming data.
This plugin uses [Ajv](https://www.npmjs.com/package/ajv), a [JSON schema](https://json-schema.org/) 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:
```shell
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](https://ajv.js.org/json-schema.html) and [formats](https://ajv.js.org/packages/ajv-formats.html)
```js
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'
};
};
```