Skip to content

Commit 2bfeefa

Browse files
committed
Updated promise resolving to Promise.all() and switched to new json-schema-ref-parser
1 parent 7aac753 commit 2bfeefa

File tree

9 files changed

+77
-56
lines changed

9 files changed

+77
-56
lines changed

package-lock.json

Lines changed: 36 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
"docker": "docker build -t eeelenbaas/openapi-typescript-codegen ."
6161
},
6262
"dependencies": {
63+
"@apidevtools/json-schema-ref-parser": "^11.1.0",
6364
"camelcase": "^6.3.0",
6465
"commander": "^11.0.0",
6566
"fs-extra": "^11.1.1",
66-
"handlebars": "^4.7.7",
67-
"json-schema-ref-parser": "^9.0.9"
67+
"handlebars": "^4.7.7"
6868
},
6969
"devDependencies": {
7070
"@angular-devkit/build-angular": "16.1.3",

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ export default {
7171
file: './dist/index.js',
7272
format: 'cjs',
7373
},
74-
external: ['camelcase', 'commander', 'fs-extra', 'handlebars', 'json-schema-ref-parser'],
74+
external: ['camelcase', 'commander', 'fs-extra', 'handlebars', '@apidevtools/json-schema-ref-parser'],
7575
plugins: getPlugins(),
7676
};

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
export 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
export 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
export 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
export 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/utils/getOpenApiSpec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import RefParser from 'json-schema-ref-parser';
1+
import RefParser from '@apidevtools/json-schema-ref-parser';
22

33
/**
44
* Load and parse te open api spec. If the file extension is ".yml" or ".yaml"

test/__snapshots__/index.spec.ts.snap

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,12 @@ export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Reso
376376
};
377377

378378
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
379-
const token = await resolve(options, config.TOKEN);
380-
const username = await resolve(options, config.USERNAME);
381-
const password = await resolve(options, config.PASSWORD);
382-
const additionalHeaders = await resolve(options, config.HEADERS);
379+
const [token, username, password, additionalHeaders] = Promise.all([
380+
resolve(options, config.TOKEN),
381+
resolve(options, config.USERNAME),
382+
resolve(options, config.PASSWORD),
383+
resolve(options, config.HEADERS),
384+
]);
383385

384386
const headers = Object.entries({
385387
Accept: 'application/json',
@@ -3469,10 +3471,12 @@ export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Reso
34693471
};
34703472

34713473
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
3472-
const token = await resolve(options, config.TOKEN);
3473-
const username = await resolve(options, config.USERNAME);
3474-
const password = await resolve(options, config.PASSWORD);
3475-
const additionalHeaders = await resolve(options, config.HEADERS);
3474+
const [token, username, password, additionalHeaders] = Promise.all([
3475+
resolve(options, config.TOKEN),
3476+
resolve(options, config.USERNAME),
3477+
resolve(options, config.PASSWORD),
3478+
resolve(options, config.HEADERS),
3479+
]);
34763480

34773481
const headers = Object.entries({
34783482
Accept: 'application/json',

0 commit comments

Comments
 (0)