Skip to content

Commit

Permalink
Ignore action/function imports referencing unknown actions/functions (#…
Browse files Browse the repository at this point in the history
…277)

* Action import without action

* Function import without function

* 0.24.2

* Update CHANGELOG.md

* Bump c8

* Update package-lock.json
  • Loading branch information
ralfhandl authored Jan 16, 2024
1 parent ed7df03 commit de92a86
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 12 additions & 3 deletions lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
72 changes: 40 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
44 changes: 44 additions & 0 deletions test/funnyInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
});

0 comments on commit de92a86

Please sign in to comment.