CDS pluginCDS plugintypeInstalls into a CAP project and extends the runtime. CAP loads it through cds.requires or the plugin hook.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

capval

Replaces the message a failed input validation annotation returns, and adds @validation.handler, which names a class that runs a check of the developer's own.

The default message for a failed @mandatory is Value is required, which in a multilevel form with many mandatory fields does not tell the user which field. @validation.message is annotated beside the standard annotations, such as @mandatory, @assert.format and @assert.range, and carries either the text or an i18n> key whose entry may hold {{Travel-EndDate}} placeholders that read values off the record under validation. @validation.handler points at a class extending BaseValidation and implementing isValid, which returns true or false; the class can read the field, its entity and a flat object of that entity and its parents up to the root, and capval works out the target and collates the errors. Those two annotations are what it introduces and there is no new constraint keyword: what a check may say is whatever isValid computes, and @mandatory and the @assert family remain @sap/cds's.

Facts

Latestv2.0.6ReleasedLast pushLicenceApache-2.0

Where it sits

Lives in
Provides
Input validationCAPInput validationcapabilityRejecting bad input before it reaches the database. While this can be done manually inside a handler, there are solutions in place to derive type, range, enum and mandatory checks from the model definitions.
Flavors
Node.jsfrom its runtime
Requires
@sap/cds≥ 8.0.0@sap/cdsartifactThe peer range, as published.

Who is behind it

MattBrightmanMattBrightmanPersonMaintains this
In the atlas: maintains 1, contributes to 1, wrote 2
@MertSAP
maintainerMichaelSchmid-AGIPersonContributes to this
In the atlas: contributes to 1
@MichaelSchmid-AGI
1 contributor

Before choosing this

Conditions

LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
  • § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
  • § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
  • § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
SAP Developer License Agreement 3.2 CAP →

What it declares

Every artifact

Type
CDS plugin
Origin
Independently maintained
Runtime
Node.js

As a CDS plugin

Declared for
>=8.0.0
Distributed through
npm

Connections1

Install

npm add capval

Derived from the package name. No recipe recorded; the README has the configuration.

Learn more2

Readings
  1. CAPVAL: A project is bornMattBrightman, SAP Community
  2. Extend SAP Cloud Application Programming Model(CAP) Validations with the CAPVAL PluginMattBrightman, SAP Community

README

quoted from MertSAP/CAPVAL under Apache-2.0, read
MertSAP/CAPVAL/README.mdOn GitHub

Extend SAP Cloud Application Programming Model(CAP) Validations with the CAPVAL Plugin

SAP CAPVAL is a SAP Cloud Application Programming Model(CAP) plugin that aims to improve and extend the standard validations provided.

This plugin aims to address the following:

  • Poor User Experience with default messages such as 'Value is required'. With a multilevel application with many mandatory fields this can leave the user feeling lost
  • Large handlers for custom validations/messages to address the above
  • Repetitive development implementing custom validations such as generating targets

Setup

To use CAPVAL, simply add the dependency to your project

For @sap/cds version less than 8.0.0 use CAPVAL version 1.1.0. Use CAPVAL version 1.2.0 and above for @sap/cds version 8.0.0 and above

npm add capval

Annotations

Custom Messages with contextual information

To override messages all we need to do is place the @validation.message annotation alongside existing input validation annotations(@mandatory,@assert.format,@assert.range...)

Examples
Custom Message
db/validations.cds

 using { sap.fe.cap.travel as schema } from '../db/schema';

annotate schema.Travel {
    @validation.message: 'Enter a valid begin date'
    @mandatory
    BeginDate;
}
Localisation

Localisation is supported and dynamic contextual information can be provided.

db/validations.cds

using { sap.fe.cap.travel as schema } from '../db/schema';

annotate schema.Travel {
    @validation.message: 'i18n>begindate-error'
    @mandatory
    BeginDate;
}

_i18n/i18n.properties

begindate-error = Enter a valid begin date
Localisation with contextual information
db/validations.cds
using { sap.fe.cap.travel as schema } from '../db/schema';

annotate schema.Travel {
    @validation.message: 'i18n>begindate-error'
    @mandatory
    BeginDate;
}

_i18n/i18n.properties
begindate-error = Begin Date required and must be before End Date {{Travel-EndDate}}

Custom Validations

The introduced annotation @validation.handler allows a class to be specified that implements a custom validation. This allows for modulisation and reuse of validations. Implementations must extend the BaseValidation class and implement the IsValid Method, returning true or false. CAPVAL will automatically determine the targets (in/to_Booking(BookingUUID etc etc), collate, and return the errors.

Example
Custom Validation

This handler checks that the begin date is before the end date

srv / handlers / BeginDateChecks.js;

const BaseValidation = require("capval");
module.exports = class BeginDateChecks extends BaseValidation {
  isValid(InputValue) {
    var travel = this.getNode();

    if (travel.BeginDate > travel.EndDate) {
      return false;
    }

    return true;
  }
};
db/validations.cds
using { sap.fe.cap.travel as schema } from '../db/schema';

annotate schema.Travel {
    @validation: {
        message: 'Please enter a begin date that is before the end date',
        handler: 'srv/handlers/BeginDateChecks.js'
    }
   BeginDate;
}
Advanced Scenario

A generic conditional validation with dynamic error messages

srv / handlers / ConditionalMandatoryCheck.js;

const BaseValidation = require("capval");
module.exports = class ConditionalMandatoryCheck extends BaseValidation {
  isValid(InputValue) {
    var data = this.getDataToRoot();
    if (data["Travel-TravelStatus_code"] === "X") return true;
    if (!InputValue) {
      this.seti18nMessage(this.getField() + "-errorMessage");
      return false;
    }
    return true;
  }
};
db/validations.cds
using { sap.fe.cap.travel as schema } from '../db/schema';
annotate schema.Travel {
    @validation: {
        message: 'Default message',
        handler: 'srv/handlers/ConditionalMandatoryCheck.js'
    }
   BeginDate;
   @validation: {
        message: 'Default message',
        handler: 'srv/handlers/ConditionalMandatoryCheck.js'
    }
   EndDate;
}

_i18n/i18n.properties
BeginDate-errorMessage = Please enter a valid begin date
EndDate-errorMessage = Please enter a valid end date
Custom Data Scenario

Custom Variables, that are not part of the Business Object can be added to provide information in messages.

srv / handlers / BeginDateChecks.js;

const BaseValidation = require("capval");
module.exports = class BeginDateChecks extends BaseValidation {
  isValid(InputValue) {
    var travel = this.getNode();
    var today = new Date().toISOString().slice(0, 10);

    if (travel.BeginDate < today) {
      this.seti18nMessage("begindatetoday-errorMessage");
      this.setCustomMessageVariables({ today: today });
      return false;
    }

    return true;
  }
};
db/validations.cds
using { sap.fe.cap.travel as schema } from '../db/schema';
annotate schema.Travel {
    @validation: {
        message: 'Please enter a begin date that is before the end date',
        handler: 'srv/handlers/BeginDateChecks.js'
    }
   BeginDate;
}

_i18n/i18n.properties
begindatetoday-errorMessage = Travel Begin Date {{Travel-BeginDate}} can not be before today {{custom-today}}
Methods

The following getter methods can be used to access information to assist with the validation:

  1. getField() : Returns the technical name of the Field getting validated. For Example: BeginDate
  2. getNode() : Returns the Entity Data for which the Field is member of. For example: The Travel Instance
  3. getMessage() : Returns the annotated error message
  4. getTarget() : Returns the calculated target
  5. getDataToRoot(): Returns a flat JSON Object(keys prefixed with the Entity Name-) of the Node under validation as well as its parents to root
  6. getData(): Returns the full data(root with all ancestors) of the instance

The following setter methods are available:

  1. setMessage(Message): Overwrites the Error Message. Variables in double curly brackets can be provided
  2. seti18nMessage(Message): Overwrites the Error Message by providing a key for an entry in the i18n.properties file
  3. setTarget(Target): Overwrites the generated field target
  4. setCustomMessageVariables(data): Allows a JSON Object with custom key value pairs to be used in error messages

Demo

SFLIGHT Scenario with CAPVAL https://github.com/MertSAP/cap-sflight

Apache-2.0, read

History

Latest

v2.0.6

  1. v2.0.5

  2. v2.0.4

    Notes

    Fixes issues with nightly test suite that runs against latest dependencies

    Suspect is was SAP/CDS 8.4.0

    Swapped out jest with mocha

  3. v2.0.3

    Notes

    Fix for issue: Typo in node_modules/capval/cds-plugin.js which breaks work of custom handlers #15

  4. v2.0.2

  5. v2.0.1

  6. v2.0.0

    Notes

    A CAPVAL version compatible with SAP CAP v8

  7. v1.2.6

    Other 2

    Notes

    Contextual Information Changes

    • Changed the error handler(non draft scenarios) to use the body of the message rather than searching in the draft table which will always return no results
    • Added a new test for contextual information
  8. v1.2.5

    Other 4

    Notes

    Expanded Test Coverage and Defect Fixes

    • Added additional tests to cover the testing of method this.seti18nMessage()
    • Added additional tests to cover the testing of method this.setCustomMessageVariables()
    • Fixed a defect where the error handler was overwriting the errors generating in on save
    • Changed the test cases for drafts to use batch input as this simulates a fiori app and triggers the custom handler
  9. v1.2.4

    Notes

    Dependency updates

  10. v1.2.3

0downloads per week, npm
Weekly downloads for capval26 complete calendar weeks from 2026-04-27 to 2026-10-25; the latest total is 0.27 Apr – 3 May: 304 May – 10 May: 4811 May – 17 May: 5618 May – 24 May: 3525 May – 31 May: 181 Jun – 7 Jun: 458 Jun – 14 Jun: 5515 Jun – 21 Jun: 2322 Jun – 28 Jun: 4529 Jun – 5 Jul: 126 Jul – 12 Jul: 5713 Jul – 19 Jul: 3220 Jul – 26 Jul: 4427 Jul – 2 Aug: 173 Aug – 9 Aug: 2610 Aug – 16 Aug: 2317 Aug – 23 Aug: 1924 Aug – 30 Aug: 1731 Aug – 6 Sept: 107 Sept – 13 Sept: 5714 Sept – 20 Sept: 1121 Sept – 27 Sept: 2328 Sept – 4 Oct: 405 Oct – 11 Oct: 2412 Oct – 18 Oct: 319 Oct – 25 Oct: 0
Input validation
  1. abapDomCheckChecks field values against domain fixed values and check tablesfrom ABAP
  2. com.sap.cds:cds-services-bomMaven bill of materials pinning CAP Java module versionsfrom CAP
  3. cap-toolkitUtility bundle for CAP handlers: builder, roles, validation, queriesfrom CAP
  4. abap-data-validatorValidation library for ABAP checking dates, emails and GUIDsfrom ABAP
  5. sap-cap-validator-pluginCAP plugin validating input against @Validator JSON Schema rulesfrom CAP
  6. cds-validateZod schemas as CAP validation middlewarefrom CAP
  7. @sap/cdsCAP Node.js runtimefrom CAP

Details

Sources4
Added by handdiscovered herechecked
npm registry, capvalversion, releases, installschecked
github.com/git+https://github.com/MertSAP/CAPVAL.gittree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
runtimesnode
declared for>=8.0.0
latestv2.0.6
first release
releases and cadence18, ~10d median
discovered viaAdded by hand
first seen in the atlas
ecosystem and domaincap, security-and-compliance
Contributors1

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent
Ref
artifact:mertsap-capval
JSON
/artifacts/mertsap-capval.json
MCP
Connecting an agent