-
Notifications
You must be signed in to change notification settings - Fork 1
02. Creating the extension
Create a new folder reCAP25extension
in the location of your choice.
Note
An Extension Project is a normal CAP project and can be run locally just like any other CAP application. The only difference is, that such project do not have their own data model, but pull a base model
from the host application in order to extend it. The CDS toolchain has some built-in convenience to achieve this.
For integrated testing, some application developers prefer to put the extension project as a subfolder of the application itself (e.g. using _ to create a top-level position) but this does not reflect the reality of extension developers, who do not have access to the base application itself
Using a terminal, cds init
will create the necessary folder structure for our extension project. Modify the package.json to reflect this:
Note the following important parts:
A workspace, which points to .base
and the extends
clause providing a resolvable name for the target application. The extension project also needs the CDS-OYSTER plugin as dependency, and code-extensibility turned on, for local testing and debugging (see later section).
The extension project is jumpstarted by pulling the base model using
cds pull --from http://localhost:4005 -u alice:
and running
npm i
to move the base model from .base
to a folder in node_modules
according to the name given in the extends
clause of package.json
.
In the db
folder of the extension project, create a file extension.cds
with the following content:
using { sap.capire.incidents as my } from '@capire/incidents';
extend my.Customers with {
status: String(8) @title: 'Customer Status';
};
You can push this extension using
cds push --to localhost:4005 -u alice:
and test it by playing around the AdminService endpoints.
In order to make testing simpler, you can use cds add http
to create useful testing requests. This will create files in the test/http
folder. To test changes on the data model, the AdminService tests are more convenient, since there is no draft support enabled there.
If you are using VS Code, the REST Client
extension allows you to run the requests directly from the editor.
In the Third exercise — Extending the model, we will start implementing the use case.