Skip to content

Commit 0ab083e

Browse files
committed
Aggregate header promises
1 parent 87f6701 commit 0ab083e

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

src/templates/core/axios/getHeaders.hbs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
2-
const token = await resolve(options, config.TOKEN);
3-
const username = await resolve(options, config.USERNAME);
4-
const password = await resolve(options, config.PASSWORD);
5-
const additionalHeaders = await resolve(options, config.HEADERS);
2+
const [token, username, password, additionalHeaders] = Promise.all([
3+
resolve(options, config.TOKEN),
4+
resolve(options, config.USERNAME),
5+
resolve(options, config.PASSWORD),
6+
resolve(options, config.HEADERS),
7+
]);
8+
69
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {}
710

811
const headers = Object.entries({

src/templates/core/fetch/getHeaders.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = await resolve(options, config.TOKEN);
3-
const username = await resolve(options, config.USERNAME);
4-
const password = await resolve(options, config.PASSWORD);
5-
const additionalHeaders = await resolve(options, config.HEADERS);
2+
const [token, username, password, additionalHeaders] = Promise.all([
3+
resolve(options, config.TOKEN),
4+
resolve(options, config.USERNAME),
5+
resolve(options, config.PASSWORD),
6+
resolve(options, config.HEADERS),
7+
]);
68

79
const headers = Object.entries({
810
Accept: 'application/json',

src/templates/core/node/getHeaders.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = await resolve(options, config.TOKEN);
3-
const username = await resolve(options, config.USERNAME);
4-
const password = await resolve(options, config.PASSWORD);
5-
const additionalHeaders = await resolve(options, config.HEADERS);
2+
const [token, username, password, additionalHeaders] = Promise.all([
3+
resolve(options, config.TOKEN),
4+
resolve(options, config.USERNAME),
5+
resolve(options, config.PASSWORD),
6+
resolve(options, config.HEADERS),
7+
]);
68

79
const headers = Object.entries({
810
Accept: 'application/json',

src/templates/core/xhr/getHeaders.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = await resolve(options, config.TOKEN);
3-
const username = await resolve(options, config.USERNAME);
4-
const password = await resolve(options, config.PASSWORD);
5-
const additionalHeaders = await resolve(options, config.HEADERS);
2+
const [token, username, password, additionalHeaders] = Promise.all([
3+
resolve(options, config.TOKEN),
4+
resolve(options, config.USERNAME),
5+
resolve(options, config.PASSWORD),
6+
resolve(options, config.HEADERS),
7+
]);
68

79
const headers = Object.entries({
810
Accept: 'application/json',

0 commit comments

Comments
 (0)