Skip to content

Commit

Permalink
fix(api-client): possibly undefined http options params and headers
Browse files Browse the repository at this point in the history
Signed-off-by: Vojtech Masek <[email protected]>
  • Loading branch information
vmasek committed May 22, 2018
1 parent af6b76e commit 539ba46
Show file tree
Hide file tree
Showing 4 changed files with 672 additions and 648 deletions.
16 changes: 11 additions & 5 deletions templates/ngx-service.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ import * as models from './models';
export const USE_DOMAIN = new InjectionToken<string>('USE_DOMAIN');
export const USE_HTTP_OPTIONS = new InjectionToken<HttpOptions>('USE_HTTP_OPTIONS');

type APIHttpOptions = HttpOptions & {
headers: HttpHeaders;
params: HttpParams;
};

/**
* Created with https://github.com/flowup/api-client-generator
*/
@Injectable()
export class APIClient {
readonly options: HttpOptions;
private domain: string = `{{&domain}}`;
readonly options: APIHttpOptions;
private readonly domain: string = `{{&domain}}`;

constructor(private http: HttpClient,
@Optional() @Inject(USE_DOMAIN) domain: string,
Expand All @@ -46,17 +52,17 @@ export class APIClient {
{{/parameters}}
},
{{/parameters.length}}
options?: HttpOptions
passedOptions?: HttpOptions
): Observable<{{&response}}> {
const path = `{{&path}}`;
options = {...this.options, ...options};
const options: APIHttpOptions = {...this.options, ...passedOptions};

{{#parameters}}
{{#isQueryParameter}}
if ('{{&camelCaseName}}' in args) {
{{#isArray}}
if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) {
options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
options.params = args.{{&camelCaseName}}.reduce<HttpParams>((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
}
{{/isArray}}
{{^isArray}}
Expand Down
Loading

0 comments on commit 539ba46

Please sign in to comment.