Skip to content

Commit 135db91

Browse files
committed
feat(api-client): optional param skipped if not in args
Signed-off-by: Vojtech Masek <vojtech.masek@flowup.cz>
1 parent 9d0cedc commit 135db91

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

templates/ngx-service.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,23 @@ export class APIClient {
5151

5252
{{#parameters}}
5353
{{#isQueryParameter}}
54-
if (args.{{&camelCaseName}}) {
54+
if ('{{&camelCaseName}}' in args) {
5555
{{#isArray}}
56-
options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
56+
if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) {
57+
options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
58+
}
5759
{{/isArray}}
5860
{{^isArray}}
5961
options.params = options.params.set('{{&name}}', String(args.{{&camelCaseName}}));
6062
{{/isArray}}
6163
}
6264
{{/isQueryParameter}}
6365
{{#isHeaderParameter}}
64-
if (args.{{&camelCaseName}}) {
66+
if ('{{&camelCaseName}}' in args) {
6567
{{#isArray}}
66-
options.headers = options.headers.set('{{&name}}', args.{{&camelCaseName}}.map(value => `${value}`));
68+
if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) {
69+
options.headers = options.headers.set('{{&name}}', args.{{&camelCaseName}}.map(value => `${value}`));
70+
}
6771
{{/isArray}}
6872
{{^isArray}}
6973
options.headers = options.headers.set('{{&name}}', String(args.{{&camelCaseName}}));

0 commit comments

Comments
 (0)