In case you missed the first blog post on CAPVAL, CAPVAL is a SAP Cloud Application Programming model plugin designed to make validations and error messages better for developers and users alike. CAPVAL introduced two new annotations. The first annotation is @validation.message. This annotation works along side standard annotations such as @mandatory and@assert.target. Here is an example:

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

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

You can read more about the features of CAPVAL here

This blog post is about CAPVAL version 2.0.  Fellow community member Michael Schmid noticed that SAP CAP version 8 contained several breaking changes for CAPVAL. Michael volunteered to help contribute to CAPVAL to help fix CAPVAL for CAP v8 and help ensure its continued support.

The main breaking change was the following:

MattBrightman_0-1724569116460.png

The solution to this was creating a custom middleware as instructed:

JavaScript
const errorHandler = async function (err, req, res, next) {
	try {
		let results = await req._query;
		await errorProcessor.generateErrors(results[0], req.locale, err);
		res.status(err.statusCode);
		res.json({ error: err });
	} catch (exception) {
		next(exception);
	}
};

cds.middlewares.after = [errorHandler];

Today we are pleased to announce the release of CAPVAL version 2.0 which is compatible with CAP v8. Although no new features have been added, a suite of changes have been made to help support CAPVAL going forward including:

  • A suite of automated tests that can be ran locally and automatically executed when Pull Requests are raised(GitHub Action).
  • Enabling Git’s Dependency Bot to update CAPVALs dependencies
  • A GitHub action to Automatically perform a NPM Publish when a new release is created and tests successfully executed.

If any of these sound helpful, even if you do not use CAPVAL, checkout the .github directory of our repository (https://github.com/MertSAP/CAPVAL) to see how these actions work. Finally if you would like to be a contributor, have any suggestions, or feature requests please let us know!
Matt and Michael

Leave a Reply

Your email address will not be published. Required fields are marked *