Skip to content

Commit

Permalink
feat(api-client): optional param skipped if not in args
Browse files Browse the repository at this point in the history
Signed-off-by: Vojtech Masek <[email protected]>
  • Loading branch information
vmasek committed Mar 14, 2018
1 parent 9d0cedc commit 135db91
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions templates/ngx-service.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ 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}}));
{{/isArray}}
}
{{/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}}));
Expand Down

0 comments on commit 135db91

Please sign in to comment.