Skip to content

Commit 5981bab

Browse files
fix: in interop-csn, remove all unknown properties from meta section (#387)
* fix: in interop-csn, remove all unknown properties According to csn-interop spec, only certain properties are allowed in section "meta". With this change, we remove all properties that are not allowed. For example, with version 6.8.0 cds-compiler adds new attribute "compilerCsnFlavor" to the meta section of CSN. This is not specified in interopCsn and thus is removed. * Update lib/interopCsn.js Co-authored-by: hyperspace-insights[bot] <209611008+hyperspace-insights[bot]@users.noreply.github.com> --------- Co-authored-by: hyperspace-insights[bot] <209611008+hyperspace-insights[bot]@users.noreply.github.com>
1 parent 999298c commit 5981bab

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

__tests__/unit/__snapshots__/interopCsn.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ exports[`interop-csn should extract service metadata 1`] = `
1212
"meta": {
1313
"__name": "MyService",
1414
"__namespace": "customer.namespace",
15+
"__privateProperty": "shouldStay",
1516
"document": {
1617
"version": "2.0.0",
1718
},
19+
"features": {
20+
"complete": true,
21+
},
1822
"flavor": "effective",
1923
},
2024
}

__tests__/unit/interopCsn.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ describe("interop-csn", () => {
5252
definitions: {
5353
"customer.namespace.MyService.v2": { kind: "service" },
5454
},
55+
meta: {
56+
creator: "shouldVanish",
57+
compilerCsnFlavor: "shouldVanish",
58+
unknownProp: "shouldVanish",
59+
__privateProperty: "shouldStay",
60+
features: {
61+
"complete": true
62+
},
63+
}
5564
};
5665
expect(interopCSN(csn)).toMatchSnapshot();
5766
});

lib/interopCsn.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,18 @@ function map_annotations(csn) {
132132
function add_meta_info(csn) {
133133
if (typeof csn != "object") return csn; // needed to make tests pass
134134
csn["csnInteropEffective"] = "1.0";
135-
csn.meta ??= {};
135+
csn.meta ??= {}; // ensure there is a meta section
136+
137+
// Keep only the properties of csn.meta that are relevant for interop:
138+
// "flavor", "document", "features", and private extension names (starting with "__")
139+
// Remove everything else, including "creator" (leaks build details) and
140+
// any unknown compiler-added properties (e.g. "compilerCsnFlavor").
141+
for (let k in csn.meta) {
142+
if (!["flavor", "document", "features"].includes(k) && !k.startsWith("__")) {
143+
delete csn.meta[k];
144+
}
145+
}
136146
csn.meta.flavor = "effective";
137-
// Remove compiler creator information – not relevant for ORD interop and leaks build details
138-
if (csn.meta.creator) delete csn.meta.creator;
139147

140148
let services = Object.entries(csn.definitions).filter(([, def]) => def.kind === "service");
141149
if (services.length === 1) {

0 commit comments

Comments
 (0)