diff --git a/.changeset/brave-eyes-suffer.md b/.changeset/brave-eyes-suffer.md new file mode 100644 index 000000000..6793737c2 --- /dev/null +++ b/.changeset/brave-eyes-suffer.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: make getHeaders() accept generic diff --git a/packages/client-axios/src/index.ts b/packages/client-axios/src/index.ts index 86f8a9970..5ce59a463 100644 --- a/packages/client-axios/src/index.ts +++ b/packages/client-axios/src/index.ts @@ -60,20 +60,23 @@ export const OpenAPI: OpenAPIConfig = { interceptors: { request: new Interceptors(), response: new Interceptors() }, }; -export const getHeaders = async ( +export const getHeaders = async ( config: OpenAPIConfig, - options: ApiRequestOptions, + options: ApiRequestOptions, ): Promise> => { const [token, username, password, additionalHeaders] = await Promise.all([ + // @ts-ignore resolve(options, config.TOKEN), + // @ts-ignore resolve(options, config.USERNAME), + // @ts-ignore resolve(options, config.PASSWORD), + // @ts-ignore resolve(options, config.HEADERS), ]); const headers = Object.entries({ Accept: 'application/json', - // @ts-ignore ...additionalHeaders, ...options.headers, }) diff --git a/packages/openapi-ts/src/templates/core/angular/getHeaders.hbs b/packages/openapi-ts/src/templates/core/angular/getHeaders.hbs index 4de2e3d4c..25ef917bf 100644 --- a/packages/openapi-ts/src/templates/core/angular/getHeaders.hbs +++ b/packages/openapi-ts/src/templates/core/angular/getHeaders.hbs @@ -1,4 +1,4 @@ -export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { +export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { return forkJoin({ // @ts-ignore token: resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/src/templates/core/axios/getHeaders.hbs b/packages/openapi-ts/src/templates/core/axios/getHeaders.hbs index 8cfa19e83..d5e5f0076 100644 --- a/packages/openapi-ts/src/templates/core/axios/getHeaders.hbs +++ b/packages/openapi-ts/src/templates/core/axios/getHeaders.hbs @@ -1,4 +1,4 @@ -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/src/templates/core/fetch/getHeaders.hbs b/packages/openapi-ts/src/templates/core/fetch/getHeaders.hbs index 9b8e220ef..5ad8e9cb5 100644 --- a/packages/openapi-ts/src/templates/core/fetch/getHeaders.hbs +++ b/packages/openapi-ts/src/templates/core/fetch/getHeaders.hbs @@ -1,4 +1,4 @@ -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/src/templates/core/xhr/getHeaders.hbs b/packages/openapi-ts/src/templates/core/xhr/getHeaders.hbs index 9b8e220ef..5ad8e9cb5 100644 --- a/packages/openapi-ts/src/templates/core/xhr/getHeaders.hbs +++ b/packages/openapi-ts/src/templates/core/xhr/getHeaders.hbs @@ -1,4 +1,4 @@ -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap index efef2a3cb..aa53f09de 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/core/request.ts.snap @@ -114,7 +114,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { +export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { return forkJoin({ // @ts-ignore token: resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular_transform/core/request.ts.snap index efef2a3cb..aa53f09de 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular_transform/core/request.ts.snap @@ -114,7 +114,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { +export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable => { return forkJoin({ // @ts-ignore token: resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap index fe71b0203..36191171a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/core/request.ts.snap @@ -117,7 +117,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios_transform/core/request.ts.snap index fe71b0203..36191171a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios_transform/core/request.ts.snap @@ -117,7 +117,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise> => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client_transform/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client_transform/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap index 788c1ae79..1b8291f98 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/core/request.ts.snap @@ -113,7 +113,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node_transform/core/request.ts.snap index 788c1ae79..1b8291f98 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node_transform/core/request.ts.snap @@ -113,7 +113,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_transform/core/request.ts.snap index 3c2af367d..f96edeeb9 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_transform/core/request.ts.snap @@ -110,7 +110,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap index dab2c96d7..7831b5bea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/core/request.ts.snap @@ -114,7 +114,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN), diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr_transform/core/request.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr_transform/core/request.ts.snap index dab2c96d7..7831b5bea 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr_transform/core/request.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr_transform/core/request.ts.snap @@ -114,7 +114,7 @@ export const resolve = async (options: ApiRequestOptions, resolver?: T | R return resolver; }; -export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { +export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { const [token, username, password, additionalHeaders] = await Promise.all([ // @ts-ignore resolve(options, config.TOKEN),