2024 Oct 09 1:13 PM - edited 2024 Oct 10 7:37 AM
In my CAP backend project I use nestjs. In version 7.9.3 of the @sap/cds and @sap/cds-dk packages, everything worked as expected. After updating these packages to version 8, an error occurs when I call my cds service: “ ERROR TypeError: Cannot read properties of undefined (reading ‘definitions’)”. The error occurs both in the $metadata and during a read operation on an entity.
The code snippet where I serve the OData service using @sap/cds framework:
async configure(_consumer: MiddlewareConsumer) {
await cds
.serve('SampleService')
.in(this.adapterHost.httpAdapter)
.from("cds")
.at('/odata')
.with(this.handler.serviceHandler);
}
You can find my project on GitHub: https://github.com/BastiInnovation/cap-template
Request clarification before answering.
Hey @BastiMankel ,
first of all, when working with @sap/cds@8.3.1 and @sap/cds-dk@8.3.0 everything works except for the $metadata request.
After debugging through your sample code with @hose versions I saw, that the metadata error is cause by the metadata middleware (@sap/cds/libx/odata/middleware/metadata.js => line 66). This relies on having either cds.context.model or cds.model being properly filled, which is not the case.
I couldn't find out, why both of which are undefined, especially since the `service` variable shows, that the model is properly loaded.
Tweeking line 66 of the metadata.js from
const csnService = (cds.context.model || cds.model).definitions[service.definition.name]
to
const csnService = (cds.context.model || cds.model || service.model).definitions[service.definition.name]
makes the metadata work again, but that is something, that needs to be addressed to the SAP team working on @sap/cds or SAP Cloud SDK, I think.
When I tried comparing the differences in that metadata middleware between @sap/cds@7.9.3 and @sap/cds@8.3.1, I noticed, that middleware is not activated in version 7.9.3 but is in 8.3.1 without having done anything within your project setup. Unfortunately, I did not find any hint on that behaviour change in the CAPire docs.
Looking forward to seeing any progress on that topic since at the moment it's blocking our migration to CAPv8...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
21 | |
9 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.