From de92a86e8757a1e991e8dfa7ff21da37613a2aba Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Tue, 16 Jan 2024 11:22:18 +0100 Subject: [PATCH] Ignore action/function imports referencing unknown actions/functions (#277) * Action import without action * Function import without function * 0.24.2 * Update CHANGELOG.md * Bump c8 * Update package-lock.json --- CHANGELOG.md | 6 ++++ lib/csdl2openapi.js | 15 +++++++-- package-lock.json | 72 +++++++++++++++++++++++------------------ package.json | 4 +-- test/funnyInput.test.js | 44 +++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d665dc7e..3fa9feca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.24.2] - 2024-01-16 + +### Fixed + +- Action/function imports referencing unknown actions/functions are ignored + ## [0.24.1] - 2023-12-20 ### Fixed diff --git a/lib/csdl2openapi.js b/lib/csdl2openapi.js index 3bfc8ff2..791a430d 100644 --- a/lib/csdl2openapi.js +++ b/lib/csdl2openapi.js @@ -1516,9 +1516,12 @@ module.exports.csdl2openapi = function ( * @param {object} child Action import object */ function pathItemActionImport(paths, name, child) { - const overload = model - .element(child.$Action) - .find((overload) => !overload.$IsBound); + const action = model.element(child.$Action); + if (!Array.isArray(action)) { + messages.push(`Unknown action ${child.$Action} in action import ${name}`); + return; + } + const overload = action.find((overload) => !overload.$IsBound); pathItemAction( paths, "/" + name, @@ -1613,6 +1616,12 @@ module.exports.csdl2openapi = function ( */ function pathItemFunctionImport(paths, name, child) { const overloads = model.element(child.$Function); + if (!Array.isArray(overloads)) { + messages.push( + `Unknown function ${child.$Function} in function import ${name}`, + ); + return; + } for (const overload of overloads) { if (overload.$IsBound) continue; pathItemFunction( diff --git a/package-lock.json b/package-lock.json index af3a9e72..c91b31c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "odata-openapi", - "version": "0.24.1", + "version": "0.24.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "odata-openapi", - "version": "0.24.1", + "version": "0.24.2", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@discoveryjs/json-ext": "^0.5.7", @@ -21,7 +21,7 @@ "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", - "c8": "^8.0.1", + "c8": "^9.1.0", "eslint": "^8.53.0", "mocha": "^10.2.0" }, @@ -140,13 +140,13 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.13", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", - "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", + "version": "0.11.14", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", + "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^2.0.1", - "debug": "^4.1.1", + "@humanwhocodes/object-schema": "^2.0.2", + "debug": "^4.3.1", "minimatch": "^3.0.5" }, "engines": { @@ -167,9 +167,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", - "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz", + "integrity": "sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==", "dev": true }, "node_modules/@istanbuljs/schema": { @@ -197,9 +197,9 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.20", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz", - "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==", + "version": "0.3.21", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.21.tgz", + "integrity": "sha512-SRfKmRe1KvYnxjEMtxEr+J4HIeMX5YBg/qhRHpxEIGjhX1rshcHlnFUE9K0GazhVKWM7B+nARSkV8LuvJdJ5/g==", "dev": true, "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", @@ -254,9 +254,9 @@ "dev": true }, "node_modules/acorn": { - "version": "8.11.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", - "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", + "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -417,19 +417,18 @@ "dev": true }, "node_modules/c8": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", - "integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz", + "integrity": "sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", "@istanbuljs/schema": "^0.1.3", "find-up": "^5.0.0", - "foreground-child": "^2.0.0", + "foreground-child": "^3.1.1", "istanbul-lib-coverage": "^3.2.0", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.6", - "rimraf": "^3.0.2", "test-exclude": "^6.0.0", "v8-to-istanbul": "^9.0.0", "yargs": "^17.7.2", @@ -439,7 +438,7 @@ "c8": "bin/c8.js" }, "engines": { - "node": ">=12" + "node": ">=14.14.0" } }, "node_modules/callsites": { @@ -928,16 +927,19 @@ "dev": true }, "node_modules/foreground-child": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", - "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", "dev": true, "dependencies": { "cross-spawn": "^7.0.0", - "signal-exit": "^3.0.2" + "signal-exit": "^4.0.1" }, "engines": { - "node": ">=8.0.0" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/fs.realpath": { @@ -1833,10 +1835,16 @@ } }, "node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } }, "node_modules/string-width": { "version": "4.2.3", diff --git a/package.json b/package.json index eaef3190..63619bf5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "odata-openapi", - "version": "0.24.1", + "version": "0.24.2", "description": "Convert OData CSDL XML or CSDL JSON to OpenAPI", "homepage": "https://github.com/oasis-tcs/odata-openapi/blob/master/lib/README.md", "bugs": "https://github.com/oasis-tcs/odata-openapi/issues", @@ -29,7 +29,7 @@ "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", - "c8": "^8.0.1", + "c8": "^9.1.0", "eslint": "^8.53.0", "mocha": "^10.2.0" }, diff --git a/test/funnyInput.test.js b/test/funnyInput.test.js index da51d4b6..c5e3aec7 100644 --- a/test/funnyInput.test.js +++ b/test/funnyInput.test.js @@ -133,4 +133,48 @@ describe("Funny input", function () { assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas"); assert.deepStrictEqual(messages, [], "messages"); }); + + it("Action/function import without action/function", function () { + const csdl = { + $Version: "4.0", + $EntityContainer: "this.Container", + this: { + Container: { + ai: { + $Action: "not.there", + }, + fi: { + $Function: "this.ct", + }, + }, + ct: { $Kind: "ComplexType" }, + }, + }; + const expected = { + paths: { + "/$batch": { post: {} }, + }, + components: { + schemas: {}, + }, + }; + const messages = []; + + const actual = csdl2openapi(csdl, { messages }); + assert.deepStrictEqual(paths(actual), paths(expected), "Paths"); + assert.deepStrictEqual( + operations(actual), + operations(expected), + "Operations", + ); + assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas"); + assert.deepStrictEqual( + messages, + [ + "Unknown action not.there in action import ai", + "Unknown function this.ct in function import fi", + ], + "messages", + ); + }); });