Skip to content

Commit 539ba46

Browse files
committed
fix(api-client): possibly undefined http options params and headers
Signed-off-by: Vojtech Masek <[email protected]>
1 parent af6b76e commit 539ba46

File tree

4 files changed

+672
-648
lines changed

4 files changed

+672
-648
lines changed

templates/ngx-service.mustache

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ import * as models from './models';
1212
export const USE_DOMAIN = new InjectionToken<string>('USE_DOMAIN');
1313
export const USE_HTTP_OPTIONS = new InjectionToken<HttpOptions>('USE_HTTP_OPTIONS');
1414

15+
type APIHttpOptions = HttpOptions & {
16+
headers: HttpHeaders;
17+
params: HttpParams;
18+
};
19+
1520
/**
1621
* Created with https://github.com/flowup/api-client-generator
1722
*/
1823
@Injectable()
1924
export class APIClient {
2025
21-
readonly options: HttpOptions;
22-
private domain: string = `{{&domain}}`;
26+
readonly options: APIHttpOptions;
27+
28+
private readonly domain: string = `{{&domain}}`;
2329

2430
constructor(private http: HttpClient,
2531
@Optional() @Inject(USE_DOMAIN) domain: string,
@@ -46,17 +52,17 @@ export class APIClient {
4652
{{/parameters}}
4753
},
4854
{{/parameters.length}}
49-
options?: HttpOptions
55+
passedOptions?: HttpOptions
5056
): Observable<{{&response}}> {
5157
const path = `{{&path}}`;
52-
options = {...this.options, ...options};
58+
const options: APIHttpOptions = {...this.options, ...passedOptions};
5359

5460
{{#parameters}}
5561
{{#isQueryParameter}}
5662
if ('{{&camelCaseName}}' in args) {
5763
{{#isArray}}
5864
if (args.{{&camelCaseName}} && args.{{&camelCaseName}}.length) {
59-
options.params = args.{{&camelCaseName}}.reduce((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
65+
options.params = args.{{&camelCaseName}}.reduce<HttpParams>((acc, cur) => acc.append('{{&name}}', `${cur}`), options.params);
6066
}
6167
{{/isArray}}
6268
{{^isArray}}

0 commit comments

Comments
 (0)