diff --git a/CHANGELOG.md b/CHANGELOG.md index a17eb11d..27ae0586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Fixed - Entity elements of named structured types are flattened when using the option `--inlineDeclarations flat` +- Properly support mandatory (`not null`) action parameters with `array of` types ## Version 0.27.0 - 2024-10-02 ### Changed diff --git a/lib/resolution/resolver.js b/lib/resolution/resolver.js index c7c794ef..bfba6199 100644 --- a/lib/resolution/resolver.js +++ b/lib/resolution/resolver.js @@ -65,7 +65,7 @@ class Resolver { * @returns {boolean} whether the type is configured to be optional */ isOptional(type) { - return !type.notNull + return type.items ? !type.items.notNull : !type.notNull } /** diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js index e26a6088..7381e803 100644 --- a/test/unit/actions.test.js +++ b/test/unit/actions.test.js @@ -178,7 +178,7 @@ describe('Actions', () => { test ('Optional Action Params', async () => { checkFunction(astwBound.tree.find(fn => fn.name === 'aMandatoryParam'), { - parameterCheck: ({members: [p1, p2, p3]}) => !check.isOptional(p1) && check.isOptional(p2) && !check.isOptional(p3), + parameterCheck: ({members: [p1, p2, p3]}) => !check.isOptional(p1) && !check.isOptional(p2) && check.isOptional(p3), }) }) diff --git a/test/unit/files/actions/model.cds b/test/unit/files/actions/model.cds index 3201cf90..cebc9445 100644 --- a/test/unit/files/actions/model.cds +++ b/test/unit/files/actions/model.cds @@ -34,9 +34,9 @@ service S { action aManyParamSingleReturn(val: array of E) returns E; action aMandatoryParam( - val: E not null, + val1: E not null, + val2: array of E not null, opt: E, - val2: E not null ) returns E; /** the action */ diff --git a/test/unit/files/actions/model.ts b/test/unit/files/actions/model.ts index 8292fe54..f6938d01 100644 --- a/test/unit/files/actions/model.ts +++ b/test/unit/files/actions/model.ts @@ -49,7 +49,7 @@ export class S extends cds.ApplicationService { async init(){ this.on(aManyParamSingleReturn, req => { const {val} = req.data; return {e1:val[0].e1} satisfies E }) this.on(aMandatoryParam, req => { - false satisfies IsKeyOptional + false satisfies IsKeyOptional false satisfies IsKeyOptional true satisfies IsKeyOptional })