Skip to content

Commit 56dbe64

Browse files
Fix array-like params in CDS functions/actions (#363)
`array of` needs to be supported as well: ```cds function check( param_2: Array of String not null ) returns ... ``` Explaining comment is [here](#332 (comment)). --------- Co-authored-by: Christian Georgi <[email protected]>
1 parent bfed040 commit 56dbe64

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1212

1313
### Fixed
1414
- Entity elements of named structured types are flattened when using the option `--inlineDeclarations flat`
15+
- Properly support mandatory (`not null`) action parameters with `array of` types
1516

1617
## Version 0.27.0 - 2024-10-02
1718
### Changed

lib/resolution/resolver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Resolver {
6565
* @returns {boolean} whether the type is configured to be optional
6666
*/
6767
isOptional(type) {
68-
return !type.notNull
68+
return type.items ? !type.items.notNull : !type.notNull
6969
}
7070

7171
/**

test/unit/actions.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('Actions', () => {
178178

179179
test ('Optional Action Params', async () => {
180180
checkFunction(astwBound.tree.find(fn => fn.name === 'aMandatoryParam'), {
181-
parameterCheck: ({members: [p1, p2, p3]}) => !check.isOptional(p1) && check.isOptional(p2) && !check.isOptional(p3),
181+
parameterCheck: ({members: [p1, p2, p3]}) => !check.isOptional(p1) && !check.isOptional(p2) && check.isOptional(p3),
182182
})
183183
})
184184

test/unit/files/actions/model.cds

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ service S {
3434
action aManyParamSingleReturn(val: array of E) returns E;
3535

3636
action aMandatoryParam(
37-
val: E not null,
37+
val1: E not null,
38+
val2: array of E not null,
3839
opt: E,
39-
val2: E not null
4040
) returns E;
4141

4242
/** the action */

test/unit/files/actions/model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class S extends cds.ApplicationService { async init(){
4949
this.on(aManyParamSingleReturn, req => { const {val} = req.data; return {e1:val[0].e1} satisfies E })
5050

5151
this.on(aMandatoryParam, req => {
52-
false satisfies IsKeyOptional<typeof req.data, 'val'>
52+
false satisfies IsKeyOptional<typeof req.data, 'val1'>
5353
false satisfies IsKeyOptional<typeof req.data, 'val2'>
5454
true satisfies IsKeyOptional<typeof req.data, 'opt'>
5555
})

0 commit comments

Comments
 (0)