diff --git a/.changeset/hot-baboons-carry.md b/.changeset/hot-baboons-carry.md new file mode 100644 index 0000000000..63b77ab263 --- /dev/null +++ b/.changeset/hot-baboons-carry.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": minor +--- + +Fix how headers are handled in @hey-api/client-angular#3860 diff --git a/examples/openapi-ts-angular-common/src/client/client/client.gen.ts b/examples/openapi-ts-angular-common/src/client/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/examples/openapi-ts-angular-common/src/client/client/client.gen.ts +++ b/examples/openapi-ts-angular-common/src/client/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/examples/openapi-ts-angular-common/src/client/client/utils.gen.ts b/examples/openapi-ts-angular-common/src/client/client/utils.gen.ts index 3809e28b1a..f1dfbaaaca 100644 --- a/examples/openapi-ts-angular-common/src/client/client/utils.gen.ts +++ b/examples/openapi-ts-angular-common/src/client/client/utils.gen.ts @@ -180,12 +180,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'], ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/examples/openapi-ts-angular/src/client/client/client.gen.ts b/examples/openapi-ts-angular/src/client/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/examples/openapi-ts-angular/src/client/client/client.gen.ts +++ b/examples/openapi-ts-angular/src/client/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/examples/openapi-ts-angular/src/client/client/utils.gen.ts b/examples/openapi-ts-angular/src/client/client/utils.gen.ts index 3809e28b1a..f1dfbaaaca 100644 --- a/examples/openapi-ts-angular/src/client/client/utils.gen.ts +++ b/examples/openapi-ts-angular/src/client/client/utils.gen.ts @@ -180,12 +180,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'], ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts +++ b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/utils.gen.ts b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/utils.gen.ts index 3809e28b1a..f1dfbaaaca 100644 --- a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/utils.gen.ts +++ b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/utils.gen.ts @@ -180,12 +180,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'], ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts index 8ffffba628..08856eab1f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/utils.gen.ts index 1fb8bc6dc1..6f4392cd08 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts index 4b2e2fa828..2bd0d6d78b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/utils.gen.ts index a8ea0fd61b..40068fa590 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts index 4b2e2fa828..2bd0d6d78b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/utils.gen.ts index a8ea0fd61b..40068fa590 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts index 2446e5d146..996415bec5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -87,6 +87,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -94,7 +106,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -105,19 +117,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -239,7 +250,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/utils.gen.ts index b9fb1a4421..a43d77a529 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/utils.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/utils.gen.ts @@ -183,12 +183,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'] ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-angular/__tests__/utils.test.ts b/packages/openapi-ts/src/plugins/@hey-api/client-angular/__tests__/utils.test.ts index 48961d1edb..f35edafe5d 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-angular/__tests__/utils.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-angular/__tests__/utils.test.ts @@ -102,7 +102,7 @@ describe('setAuthParams', () => { }, ], }; - await setAuthParams(options); + await setAuthParams(options, options.security); expect(auth).toHaveBeenCalled(); expect(options.headers.get('baz')).toBe('Bearer foo'); expect(Object.keys(query).length).toBe(0); @@ -112,11 +112,13 @@ describe('setAuthParams', () => { const auth = vi.fn().mockReturnValue('foo'); const headers = new HttpHeaders(); const query: Record = {}; - await setAuthParams({ - auth, - headers, - query, - security: [ + await setAuthParams( + { + auth, + headers, + query, + }, + [ { in: 'query', name: 'baz', @@ -124,7 +126,7 @@ describe('setAuthParams', () => { type: 'http', }, ], - }); + ); expect(auth).toHaveBeenCalled(); expect(headers.get('baz')).toBeNull(); expect(query.baz).toBe('Bearer foo'); @@ -144,7 +146,7 @@ describe('setAuthParams', () => { }, ], }; - await setAuthParams(options); + await setAuthParams(options, options.security); expect(auth).toHaveBeenCalled(); expect(options.headers.get('Authorization')).toBe('foo'); expect(query).toEqual({}); @@ -172,7 +174,7 @@ describe('setAuthParams', () => { }, ], }; - await setAuthParams(options); + await setAuthParams(options, options.security); expect(auth).toHaveBeenCalled(); expect(options.headers.get('baz')).toBe('Bearer foo'); expect(Object.keys(query).length).toBe(0); @@ -187,11 +189,13 @@ describe('setAuthParams', () => { }); const headers = new HttpHeaders(); const query: Record = {}; - await setAuthParams({ - auth, - headers, - query, - security: [ + await setAuthParams( + { + auth, + headers, + query, + }, + [ { name: 'baz', type: 'apiKey', @@ -203,7 +207,7 @@ describe('setAuthParams', () => { type: 'http', }, ], - }); + ); expect(auth).toHaveBeenCalled(); expect(headers.get('baz')).toBeNull(); expect(query.baz).toBe('Bearer foo'); @@ -225,7 +229,7 @@ describe('setAuthParams', () => { }, ], }; - await setAuthParams(options); + await setAuthParams(options, options.security); expect(auth).toHaveBeenCalled(); expect(options.headers.get('Cookie')).toBe('baz=foo'); expect(query).toEqual({}); diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts index 91136abca8..7f0bdf3ffa 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts @@ -1,4 +1,4 @@ -import type { HttpResponse } from '@angular/common/http'; +import type { HttpHeaders, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http'; import { assertInInjectionContext, @@ -85,6 +85,18 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } + return opts; + }; + + const finalizeRequest = < + TData = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', + >( + opts: RequestOptions & { + headers: HttpHeaders; + }, + ) => { const url = buildUrl(opts as Config & RequestOptions); const req = new HttpRequest(opts.method ?? 'GET', url, getValidRequestBody(opts), { @@ -92,7 +104,7 @@ export const createClient = (config: Config = {}): Client => { ...opts, }); - return { opts, req, url }; + return { req, url }; }; const beforeRequest = async < @@ -103,19 +115,18 @@ export const createClient = (config: Config = {}): Client => { >( options: RequestOptions, ) => { - const { opts, req, url } = requestOptions(options); + const opts = requestOptions(options); if (opts.security) { - await setAuthParams({ - ...opts, - security: opts.security, - }); + await setAuthParams(opts, opts.security); } if (opts.requestValidator) { await opts.requestValidator(opts); } + const { req, url } = finalizeRequest(opts); + return { opts, req, url }; }; @@ -237,7 +248,7 @@ export const createClient = (config: Config = {}): Client => { throw new Error('Request validation is not supported in requestOptions'); } - return requestOptions(options).req; + return finalizeRequest(requestOptions(options)).req; }, setConfig, sse: { diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/utils.ts b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/utils.ts index d8f2897334..ee12e7c214 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/utils.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/utils.ts @@ -181,12 +181,12 @@ export const getParseAs = ( }; export const setAuthParams = async ( - options: Pick, 'security'> & - Pick & { - headers: HttpHeaders; - }, + options: Pick & { + headers: HttpHeaders; + }, + security: Pick, 'security'>['security'], ) => { - for (const auth of options.security) { + for (const auth of security) { const token = await getAuthToken(auth, options.auth); if (!token) { @@ -210,8 +210,6 @@ export const setAuthParams = async ( options.headers = options.headers.set(name, token); break; } - - return; } };