From fb759e347304424bc403fecbf77bced602b4ed1f Mon Sep 17 00:00:00 2001 From: Steffen Weinstock <79531202+stewsk@users.noreply.github.com> Date: Thu, 22 May 2025 16:47:40 +0200 Subject: [PATCH 1/2] Produce interopCSN --- lib/build.js | 2 +- lib/interop-csn.js | 35 +++++++++++++++++++++++++++++++++++ lib/metaData.js | 4 +++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/interop-csn.js diff --git a/lib/build.js b/lib/build.js index e5006693..a4a53d6e 100644 --- a/lib/build.js +++ b/lib/build.js @@ -12,7 +12,7 @@ module.exports = class OrdBuildPlugin extends cds_dk.build.Plugin { } async _writeResourcesFiles(resObj, model, promises) { - for (const resource of resObj) { + for (const resource of resObj || []) { if (resource.ordId.includes(ORD_SERVICE_NAME) || !resource.resourceDefinitions) { continue; } diff --git a/lib/interop-csn.js b/lib/interop-csn.js new file mode 100644 index 00000000..f497c7a0 --- /dev/null +++ b/lib/interop-csn.js @@ -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"; + 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]) { + if (!o[newA]) o[newA] = o[oldA]; + delete o[oldA]; + } + } +} + +module.exports = { + interopCSN +}; diff --git a/lib/metaData.js b/lib/metaData.js index 8d18cd50..59376c84 100644 --- a/lib/metaData.js +++ b/lib/metaData.js @@ -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) => { @@ -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; From 50ef6540f1320b1b193b1b5b090f5d61e33f6dca Mon Sep 17 00:00:00 2001 From: Steffen Weinstock <79531202+stewsk@users.noreply.github.com> Date: Thu, 22 May 2025 16:54:54 +0200 Subject: [PATCH 2/2] nicer --- lib/interop-csn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/interop-csn.js b/lib/interop-csn.js index f497c7a0..21976b5e 100644 --- a/lib/interop-csn.js +++ b/lib/interop-csn.js @@ -24,7 +24,7 @@ function replaceAnnos(o) { for (const [oldA, newA] of Object.entries(annoReplacement)) { if (o[oldA]) { - if (!o[newA]) o[newA] = o[oldA]; + o[newA] ??= o[oldA]; delete o[oldA]; } }