Skip to content

Commit 55dab80

Browse files
committed
update examples
1 parent 60dd08a commit 55dab80

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

examples/petstore-v2.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Auto-generated by https://github.com/vladkens/apigen-ts
22
// Source: https://petstore.swagger.io/v2/swagger.json
33

4+
type Headers = Record<string, string>
5+
export type ApigenHeaders = Headers | ((method: string, path: string) => Headers | Promise<Headers>)
6+
47
export interface ApigenConfig {
58
baseUrl: string
6-
headers: Record<string, string>
9+
headers: ApigenHeaders
710
}
811

912
export interface ApigenRequest extends Omit<RequestInit, "body"> {
@@ -56,7 +59,12 @@ export class ApiClient {
5659
url.searchParams.append(k, Array.isArray(v) ? v.join(",") : (v as string))
5760
}
5861

59-
const headers = new Headers({ ...this.Config.headers, ...opts.headers })
62+
const configHeaders =
63+
typeof this.Config.headers === "function"
64+
? await this.Config.headers(method, path)
65+
: this.Config.headers
66+
67+
const headers = new Headers({ ...configHeaders, ...opts.headers })
6068
const ct = headers.get("content-type") ?? "application/json"
6169

6270
let body: FormData | URLSearchParams | string | undefined = undefined

examples/petstore-v3.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Auto-generated by https://github.com/vladkens/apigen-ts
22
// Source: https://petstore3.swagger.io/api/v3/openapi.json
33

4+
type Headers = Record<string, string>
5+
export type ApigenHeaders = Headers | ((method: string, path: string) => Headers | Promise<Headers>)
6+
47
export interface ApigenConfig {
58
baseUrl: string
6-
headers: Record<string, string>
9+
headers: ApigenHeaders
710
}
811

912
export interface ApigenRequest extends Omit<RequestInit, "body"> {
@@ -56,7 +59,12 @@ export class ApiClient {
5659
url.searchParams.append(k, Array.isArray(v) ? v.join(",") : (v as string))
5760
}
5861

59-
const headers = new Headers({ ...this.Config.headers, ...opts.headers })
62+
const configHeaders =
63+
typeof this.Config.headers === "function"
64+
? await this.Config.headers(method, path)
65+
: this.Config.headers
66+
67+
const headers = new Headers({ ...configHeaders, ...opts.headers })
6068
const ct = headers.get("content-type") ?? "application/json"
6169

6270
let body: FormData | URLSearchParams | string | undefined = undefined

0 commit comments

Comments
 (0)