on ‎2024 Aug 01 8:06 PM
Hi,
We are upgrading a CAP project from CDS7 to CDS8 where we have programmatic adjustments to the services metadata. Like this
// In custom server.js
const cds = require('@sap/cds');
module.exports = (o) => {
// ...
cds.on('loaded', csn => {
Object.entries(csn.definitions).forEach(([rootName, def]) => {
// Code to enhance annotations goes here ...
});
});
// ...
// delegate to default server
return cds.server(o);
}These stopped working with CDS8 which seems to be due to the metadata being generated at compile time. In the gen/srv folder we get ready-made "MyService.xml" files in a "odata/v4" subfolder, and it seems the service uses these, making our startup adjustments not apply.
For now we have avoided the issue by disabling those build items, like that in package.json
{
...
"cds": {
"build": {
"tasks": [
{
"for": "hana"
},
{
"for": "nodejs",
"options": {
"contentEdmx": false
}
}
]
},
...
}We would like to use this new feature (it reduces application load time etc.), but we are then looking for a way to plug in such model adjustments during build. Is there such a way?
Thanks!
//Carl
Request clarification before answering.
I saw this method of making changes to the model in loaded event working in a plugin even with cds v8 with change-tracking plugin (main branch/v1.0.7[yet to be released]). The changes are present already in the saved model (csn.json) after build. So, you have to ensure that the change is not done again if the model is loaded from a built csn.json with these changes.
Perhaps you could move your code for modifications to a plugin so that it is activated during build as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.