From 135db914866dd71fb222a9f6aa5637fb54d8546a Mon Sep 17 00:00:00 2001 From: Vojtech Masek Date: Wed, 14 Mar 2018 15:08:36 +0100 Subject: [PATCH] feat(api-client): optional param skipped if not in args Signed-off-by: Vojtech Masek --- templates/ngx-service.mustache | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/templates/ngx-service.mustache b/templates/ngx-service.mustache index 682a72a7..ecdf1403 100644 --- a/templates/ngx-service.mustache +++ b/templates/ngx-service.mustache @@ -51,9 +51,11 @@ export class APIClient { {{#parameters}} {{#isQueryParameter}} - if (args.{{&camelCaseName}}) { + if ('{{&camelCaseName}}' in args) { {{#isArray}} - options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params); + if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) { + options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params); + } {{/isArray}} {{^isArray}} options.params = options.params.set('{{&name}}', String(args.{{&camelCaseName}})); @@ -61,9 +63,11 @@ export class APIClient { } {{/isQueryParameter}} {{#isHeaderParameter}} - if (args.{{&camelCaseName}}) { + if ('{{&camelCaseName}}' in args) { {{#isArray}} - options.headers = options.headers.set('{{&name}}', args.{{&camelCaseName}}.map(value => `${value}`)); + if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) { + options.headers = options.headers.set('{{&name}}', args.{{&camelCaseName}}.map(value => `${value}`)); + } {{/isArray}} {{^isArray}} options.headers = options.headers.set('{{&name}}', String(args.{{&camelCaseName}}));