Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/interop-csn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

function interopCSN(csn) {

for (let dn in csn.definitions) {
let def = csn.definitions[dn];
replaceAnnos(def);
if (def.kind === "entity")
for (let en in def.elements) {
let el = def.elements[en];
replaceAnnos(el);
}
}

csn["csnInteropEffective"] = "1.0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stewsk : we would need meta.document.version, I would propose to take it from the data source annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't that be the version of the data product itself rather than the data source?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it needs to go into meta.document.version, or if we have a CDS Service, the version number could be added as annotation there (is there some annotation in CAP to add a full version to a service?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have a CDS Service

In CAP, for a Data Product there always is a service

is there some annotation in CAP to add a full version to a service?

no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, it is more the version of the data product. We should probably have a sync on the detailed content for the meta section (incl. name + namespace)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary of the sync between @stewsk and @swennemers :

meta:{
    "__name": "<service name>", // clarify if it should be 
    "__namespace": "<service namespace>",//service namespace should be in line with namespace registry namespace as this is a newly build service for data products.
    "document": {
      "version": "1.0.0" //CAP service version / application version or start hard coded.
    }

for the dpd files, that cut this csn per entity, the name and version must reflect the data source name, namespace and version that is maintained on the entity level.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expose this at all on CAP level? You'll describe the service in ORD as well and then the ORD information and ORD ID would already contain the information.

return csn;
}


function replaceAnnos(o) {
const annoReplacement = {
"@Common.Label": "@EndUserText.label",
"@title": "@EndUserText.label",
};

for (const [oldA, newA] of Object.entries(annoReplacement)) {
if (o[oldA]) {
o[newA] ??= o[oldA];
delete o[oldA];
}
}
}

module.exports = {
interopCSN
};
4 changes: 3 additions & 1 deletion lib/metaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { compile: openapi } = require("@cap-js/openapi");
const { compile: asyncapi } = require("@cap-js/asyncapi");
const { COMPILER_TYPES } = require("./constants");
const { Logger } = require("./logger");
const { interopCSN } = require("./interop-csn.js");
const cdsc = require("@sap/cds-compiler/lib/main");

module.exports = async (url, model = null) => {
Expand Down Expand Up @@ -37,7 +38,8 @@ module.exports = async (url, model = null) => {
case COMPILER_TYPES.csn:
try {
const opt2 = { beta: { effectiveCsn: true }, effectiveServiceName: serviceName };
responseFile = cdsc.for.effective(csn, opt2);
let effCsn = cdsc.for.effective(csn, opt2);
responseFile = interopCSN(effCsn);
} catch (error) {
Logger.error("Csn error:", error.message);
throw error;
Expand Down
Loading