Skip to content

Commit 8915770

Browse files
committed
- Eslint fixes
1 parent 017de0e commit 8915770

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

src/templates/core/angular/getHeaders.hbs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,41 @@ const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observab
44
username: resolve(options, config.USERNAME),
55
password: resolve(options, config.PASSWORD),
66
additionalHeaders: resolve(options, config.HEADERS),
7-
})
8-
.pipe(
9-
map(({ token, username, password, additionalHeaders }) => {
10-
const headers = Object.entries({
11-
Accept: 'application/json',
12-
...additionalHeaders,
13-
...options.headers,
14-
})
15-
.filter(([_, value]) => isDefined(value))
16-
.reduce((headers, [key, value]) => ({
17-
...headers,
18-
[key]: String(value),
19-
}), {} as Record<string, string>);
7+
}).pipe(
8+
map(({ token, username, password, additionalHeaders }) => {
9+
const headers = Object.entries({
10+
Accept: 'application/json',
11+
...additionalHeaders,
12+
...options.headers,
13+
})
14+
.filter(([_, value]) => isDefined(value))
15+
.reduce((headers, [key, value]) => ({
16+
...headers,
17+
[key]: String(value),
18+
}), {} as Record<string, string>);
2019

21-
if (isStringWithValue(token)) {
22-
headers['Authorization'] = `Bearer ${token}`;
23-
}
20+
if (isStringWithValue(token)) {
21+
headers['Authorization'] = `Bearer ${token}`;
22+
}
2423

25-
if (isStringWithValue(username) && isStringWithValue(password)) {
26-
const credentials = base64(`${username}:${password}`);
27-
headers['Authorization'] = `Basic ${credentials}`;
28-
}
24+
if (isStringWithValue(username) && isStringWithValue(password)) {
25+
const credentials = base64(`${username}:${password}`);
26+
headers['Authorization'] = `Basic ${credentials}`;
27+
}
2928

30-
if (options.body) {
31-
if (options.mediaType) {
32-
headers['Content-Type'] = options.mediaType;
33-
} else if (isBlob(options.body)) {
34-
headers['Content-Type'] = options.body.type || 'application/octet-stream';
35-
} else if (isString(options.body)) {
36-
headers['Content-Type'] = 'text/plain';
37-
} else if (!isFormData(options.body)) {
38-
headers['Content-Type'] = 'application/json';
39-
}
29+
if (options.body) {
30+
if (options.mediaType) {
31+
headers['Content-Type'] = options.mediaType;
32+
} else if (isBlob(options.body)) {
33+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
34+
} else if (isString(options.body)) {
35+
headers['Content-Type'] = 'text/plain';
36+
} else if (!isFormData(options.body)) {
37+
headers['Content-Type'] = 'application/json';
4038
}
39+
}
4140

42-
return new HttpHeaders(headers);
43-
})
44-
);
41+
return new HttpHeaders(headers);
42+
}),
43+
);
4544
};

0 commit comments

Comments
 (0)