Skip to content

Commit

Permalink
Merge branch 'main' into feat/keep
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Jan 16, 2024
2 parents 17fde13 + de92a86 commit 05136be
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
- Deep paths to stubbed entity types are omitted.
- The `/$batch` resource is omitted.

## [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 @@ -1535,9 +1535,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 @@ -1632,6 +1635,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
70 changes: 39 additions & 31 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
Expand Up @@ -29,8 +29,8 @@
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^2.1.1",
"c8": "^8.0.1",
"eslint": "^8.55.0",
"c8": "^9.1.0",
"eslint": "^8.56.0",
"mocha": "^10.2.0"
},
"scripts": {
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 05136be

Please sign in to comment.