@kubb/plugin-client 4.22.3 → 4.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{StaticClassClient-DEcg6Vjq.cjs → StaticClassClient-D7DWLX5M.cjs} +8 -8
  2. package/dist/StaticClassClient-D7DWLX5M.cjs.map +1 -0
  3. package/dist/{StaticClassClient-mL_MpTJQ.js → StaticClassClient-InXfCDQs.js} +8 -8
  4. package/dist/StaticClassClient-InXfCDQs.js.map +1 -0
  5. package/dist/clients/axios.cjs +14 -9
  6. package/dist/clients/axios.cjs.map +1 -1
  7. package/dist/clients/axios.d.cts +2 -1
  8. package/dist/clients/axios.d.ts +2 -1
  9. package/dist/clients/axios.js +14 -10
  10. package/dist/clients/axios.js.map +1 -1
  11. package/dist/clients/fetch.cjs +14 -9
  12. package/dist/clients/fetch.cjs.map +1 -1
  13. package/dist/clients/fetch.d.cts +2 -1
  14. package/dist/clients/fetch.d.ts +2 -1
  15. package/dist/clients/fetch.js +14 -10
  16. package/dist/clients/fetch.js.map +1 -1
  17. package/dist/components.cjs +1 -1
  18. package/dist/components.js +1 -1
  19. package/dist/{generators-tEaQeAYN.js → generators-C1oQgrxL.js} +82 -52
  20. package/dist/generators-C1oQgrxL.js.map +1 -0
  21. package/dist/{generators-D_u4tfoM.cjs → generators-Y1Tc5B1O.cjs} +82 -52
  22. package/dist/generators-Y1Tc5B1O.cjs.map +1 -0
  23. package/dist/generators.cjs +1 -1
  24. package/dist/generators.js +1 -1
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.js +1 -1
  27. package/package.json +6 -6
  28. package/src/clients/axios.ts +16 -14
  29. package/src/clients/fetch.ts +14 -9
  30. package/src/components/ClassClient.tsx +6 -6
  31. package/src/components/StaticClassClient.tsx +5 -5
  32. package/src/generators/__snapshots__/Pet.ts +20 -19
  33. package/src/generators/__snapshots__/Store.ts +14 -13
  34. package/src/generators/__snapshots__/User.ts +18 -17
  35. package/src/generators/__snapshots__/static/Pet.ts +19 -18
  36. package/src/generators/__snapshots__/static/Store.ts +13 -12
  37. package/src/generators/__snapshots__/static/User.ts +17 -16
  38. package/src/generators/classClientGenerator.tsx +3 -1
  39. package/src/generators/staticClassClientGenerator.tsx +3 -1
  40. package/templates/clients/axios.ts +15 -13
  41. package/templates/clients/fetch.ts +14 -9
  42. package/dist/StaticClassClient-DEcg6Vjq.cjs.map +0 -1
  43. package/dist/StaticClassClient-mL_MpTJQ.js.map +0 -1
  44. package/dist/generators-D_u4tfoM.cjs.map +0 -1
  45. package/dist/generators-tEaQeAYN.js.map +0 -1
@@ -46,25 +46,27 @@ export const setConfig = (config: RequestConfig) => {
46
46
  return getConfig()
47
47
  }
48
48
 
49
+ export const mergeConfig = <T extends RequestConfig>(...configs: Array<Partial<T>>): Partial<T> => {
50
+ return configs.reduce<Partial<T>>((merged, config) => {
51
+ return {
52
+ ...merged,
53
+ ...config,
54
+ headers: {
55
+ ...merged.headers,
56
+ ...config.headers,
57
+ },
58
+ }
59
+ }, {})
60
+ }
61
+
49
62
  export const axiosInstance = axios.create(getConfig())
50
63
 
51
64
  export const client = async <TResponseData, TError = unknown, TRequestData = unknown>(
52
65
  config: RequestConfig<TRequestData>,
53
66
  ): Promise<ResponseConfig<TResponseData>> => {
54
- const globalConfig = getConfig()
55
-
56
- return axiosInstance
57
- .request<TResponseData, ResponseConfig<TResponseData>>({
58
- ...globalConfig,
59
- ...config,
60
- headers: {
61
- ...globalConfig.headers,
62
- ...config.headers,
63
- },
64
- })
65
- .catch((e: AxiosError<TError>) => {
66
- throw e
67
- })
67
+ return axiosInstance.request<TResponseData, ResponseConfig<TResponseData>>(mergeConfig(getConfig(), config)).catch((e: AxiosError<TError>) => {
68
+ throw e
69
+ })
68
70
  }
69
71
 
70
72
  client.getConfig = getConfig
@@ -37,6 +37,19 @@ export const setConfig = (config: Partial<RequestConfig>) => {
37
37
  return getConfig()
38
38
  }
39
39
 
40
+ export const mergeConfig = <T extends RequestConfig>(...configs: Array<Partial<T>>): Partial<T> => {
41
+ return configs.reduce<Partial<T>>((merged, config) => {
42
+ return {
43
+ ...merged,
44
+ ...config,
45
+ headers: {
46
+ ...(Array.isArray(merged.headers) ? Object.fromEntries(merged.headers) : merged.headers),
47
+ ...(Array.isArray(config.headers) ? Object.fromEntries(config.headers) : config.headers),
48
+ },
49
+ }
50
+ }, {})
51
+ }
52
+
40
53
  export type ResponseErrorConfig<TError = unknown> = TError
41
54
 
42
55
  export type Client = <TResponseData, _TError = unknown, TRequestData = unknown>(config: RequestConfig<TRequestData>) => Promise<ResponseConfig<TResponseData>>
@@ -46,15 +59,7 @@ export const client = async <TResponseData, _TError = unknown, RequestData = unk
46
59
  ): Promise<ResponseConfig<TResponseData>> => {
47
60
  const normalizedParams = new URLSearchParams()
48
61
 
49
- const globalConfig = getConfig()
50
- const config = {
51
- ...globalConfig,
52
- ...paramsConfig,
53
- headers: {
54
- ...(Array.isArray(globalConfig.headers) ? Object.fromEntries(globalConfig.headers) : globalConfig.headers),
55
- ...(Array.isArray(paramsConfig.headers) ? Object.fromEntries(paramsConfig.headers) : paramsConfig.headers),
56
- },
57
- }
62
+ const config = mergeConfig(getConfig(), paramsConfig)
58
63
 
59
64
  Object.entries(config.params || {}).forEach(([key, value]) => {
60
65
  if (value !== undefined) {
@@ -74,6 +74,9 @@ function buildClientParams({
74
74
  config: {
75
75
  mode: 'object',
76
76
  children: {
77
+ requestConfig: {
78
+ mode: 'inlineSpread',
79
+ },
77
80
  method: {
78
81
  value: JSON.stringify(operation.method.toUpperCase()),
79
82
  },
@@ -91,9 +94,6 @@ function buildClientParams({
91
94
  value: isFormData ? 'formData as FormData' : 'requestData',
92
95
  }
93
96
  : undefined,
94
- requestConfig: {
95
- mode: 'inlineSpread',
96
- },
97
97
  headers: headers.length
98
98
  ? {
99
99
  value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,
@@ -173,7 +173,7 @@ function generateMethod({
173
173
  const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })
174
174
 
175
175
  const methodBody = [
176
- 'const { client: request = this.#client, ...requestConfig } = config',
176
+ 'const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)',
177
177
  '',
178
178
  requestDataLine,
179
179
  formDataLine,
@@ -216,10 +216,10 @@ export function ClassClient({
216
216
  )
217
217
 
218
218
  const classCode = `export class ${name} {
219
- #client: Client
219
+ #config: Partial<RequestConfig> & { client?: Client }
220
220
 
221
221
  constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
222
- this.#client = config.client || fetch
222
+ this.#config = config
223
223
  }
224
224
 
225
225
  ${methods.join('\n\n')}
@@ -70,6 +70,9 @@ function buildClientParams({
70
70
  config: {
71
71
  mode: 'object',
72
72
  children: {
73
+ requestConfig: {
74
+ mode: 'inlineSpread',
75
+ },
73
76
  method: {
74
77
  value: JSON.stringify(operation.method.toUpperCase()),
75
78
  },
@@ -87,9 +90,6 @@ function buildClientParams({
87
90
  value: isFormData ? 'formData as FormData' : 'requestData',
88
91
  }
89
92
  : undefined,
90
- requestConfig: {
91
- mode: 'inlineSpread',
92
- },
93
93
  headers: headers.length
94
94
  ? {
95
95
  value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,
@@ -169,7 +169,7 @@ function generateMethod({
169
169
  const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })
170
170
 
171
171
  const methodBody = [
172
- 'const { client: request = this.#client, ...requestConfig } = config',
172
+ 'const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)',
173
173
  '',
174
174
  requestDataLine,
175
175
  formDataLine,
@@ -212,7 +212,7 @@ export function StaticClassClient({
212
212
  }),
213
213
  )
214
214
 
215
- const classCode = `export class ${name} {\n static #client: Client = fetch\n\n${methods.join('\n\n')}\n}`
215
+ const classCode = `export class ${name} {\n static #config: Partial<RequestConfig> & { client?: Client } = {}\n\n${methods.join('\n\n')}\n}`
216
216
 
217
217
  return (
218
218
  <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
@@ -2,6 +2,7 @@
2
2
  * Generated by Kubb (https://kubb.dev/).
3
3
  * Do not edit manually.
4
4
  */
5
+ import fetch from './test/.kubb/fetch'
5
6
  import type { Client, RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
6
7
  import type {
7
8
  UpdatePetMutationRequest,
@@ -36,13 +37,13 @@ import type {
36
37
  UploadFileQueryParams,
37
38
  } from './findByTags'
38
39
  import { buildFormData } from './test/.kubb/config'
39
- import { fetch } from './test/.kubb/fetch'
40
+ import { mergeConfig } from './test/.kubb/fetch'
40
41
 
41
42
  export class Pet {
42
- #client: Client
43
+ #config: Partial<RequestConfig> & { client?: Client }
43
44
 
44
45
  constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
45
- this.#client = config.client || fetch
46
+ this.#config = config
46
47
  }
47
48
 
48
49
  /**
@@ -51,13 +52,13 @@ export class Pet {
51
52
  * {@link /pet}
52
53
  */
53
54
  async updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> & { client?: Client } = {}) {
54
- const { client: request = this.#client, ...requestConfig } = config
55
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
55
56
  const requestData = data
56
57
  const res = await request<UpdatePetMutationResponse, ResponseErrorConfig<UpdatePet400 | UpdatePet404 | UpdatePet405>, UpdatePetMutationRequest>({
58
+ ...requestConfig,
57
59
  method: 'PUT',
58
60
  url: `/pet`,
59
61
  data: requestData,
60
- ...requestConfig,
61
62
  })
62
63
  return res.data
63
64
  }
@@ -68,13 +69,13 @@ export class Pet {
68
69
  * {@link /pet}
69
70
  */
70
71
  async addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> & { client?: Client } = {}) {
71
- const { client: request = this.#client, ...requestConfig } = config
72
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
72
73
  const requestData = data
73
74
  const res = await request<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, AddPetMutationRequest>({
75
+ ...requestConfig,
74
76
  method: 'POST',
75
77
  url: `/pet`,
76
78
  data: requestData,
77
- ...requestConfig,
78
79
  })
79
80
  return res.data
80
81
  }
@@ -85,12 +86,12 @@ export class Pet {
85
86
  * {@link /pet/findByStatus}
86
87
  */
87
88
  async findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
88
- const { client: request = this.#client, ...requestConfig } = config
89
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
89
90
  const res = await request<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, unknown>({
91
+ ...requestConfig,
90
92
  method: 'GET',
91
93
  url: `/pet/findByStatus`,
92
94
  params,
93
- ...requestConfig,
94
95
  })
95
96
  return res.data
96
97
  }
@@ -101,12 +102,12 @@ export class Pet {
101
102
  * {@link /pet/findByTags}
102
103
  */
103
104
  async findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
104
- const { client: request = this.#client, ...requestConfig } = config
105
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
105
106
  const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
107
+ ...requestConfig,
106
108
  method: 'GET',
107
109
  url: `/pet/findByTags`,
108
110
  params,
109
- ...requestConfig,
110
111
  })
111
112
  return res.data
112
113
  }
@@ -117,11 +118,11 @@ export class Pet {
117
118
  * {@link /pet/:petId}
118
119
  */
119
120
  async getPetById(petId: GetPetByIdPathParams['petId'], config: Partial<RequestConfig> & { client?: Client } = {}) {
120
- const { client: request = this.#client, ...requestConfig } = config
121
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
121
122
  const res = await request<GetPetByIdQueryResponse, ResponseErrorConfig<GetPetById400 | GetPetById404>, unknown>({
123
+ ...requestConfig,
122
124
  method: 'GET',
123
125
  url: `/pet/${petId}`,
124
- ...requestConfig,
125
126
  })
126
127
  return res.data
127
128
  }
@@ -135,12 +136,12 @@ export class Pet {
135
136
  params?: UpdatePetWithFormQueryParams,
136
137
  config: Partial<RequestConfig> & { client?: Client } = {},
137
138
  ) {
138
- const { client: request = this.#client, ...requestConfig } = config
139
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
139
140
  const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, unknown>({
141
+ ...requestConfig,
140
142
  method: 'POST',
141
143
  url: `/pet/${petId}`,
142
144
  params,
143
- ...requestConfig,
144
145
  })
145
146
  return res.data
146
147
  }
@@ -151,11 +152,11 @@ export class Pet {
151
152
  * {@link /pet/:petId}
152
153
  */
153
154
  async deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
154
- const { client: request = this.#client, ...requestConfig } = config
155
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
155
156
  const res = await request<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
157
+ ...requestConfig,
156
158
  method: 'DELETE',
157
159
  url: `/pet/${petId}`,
158
- ...requestConfig,
159
160
  headers: { ...headers, ...requestConfig.headers },
160
161
  })
161
162
  return res.data
@@ -171,15 +172,15 @@ export class Pet {
171
172
  params?: UploadFileQueryParams,
172
173
  config: Partial<RequestConfig<UploadFileMutationRequest>> & { client?: Client } = {},
173
174
  ) {
174
- const { client: request = this.#client, ...requestConfig } = config
175
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
175
176
  const requestData = data
176
177
  const formData = buildFormData(requestData)
177
178
  const res = await request<UploadFileMutationResponse, ResponseErrorConfig<Error>, UploadFileMutationRequest>({
179
+ ...requestConfig,
178
180
  method: 'POST',
179
181
  url: `/pet/${petId}/uploadImage`,
180
182
  params,
181
183
  data: formData as FormData,
182
- ...requestConfig,
183
184
  })
184
185
  return res.data
185
186
  }
@@ -2,6 +2,7 @@
2
2
  * Generated by Kubb (https://kubb.dev/).
3
3
  * Do not edit manually.
4
4
  */
5
+ import fetch from './test/.kubb/fetch'
5
6
  import type { Client, RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
6
7
  import type {
7
8
  GetInventoryQueryResponse,
@@ -20,13 +21,13 @@ import type {
20
21
  DeleteOrder400,
21
22
  DeleteOrder404,
22
23
  } from './findByTags'
23
- import { fetch } from './test/.kubb/fetch'
24
+ import { mergeConfig } from './test/.kubb/fetch'
24
25
 
25
26
  export class Store {
26
- #client: Client
27
+ #config: Partial<RequestConfig> & { client?: Client }
27
28
 
28
29
  constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
29
- this.#client = config.client || fetch
30
+ this.#config = config
30
31
  }
31
32
 
32
33
  /**
@@ -35,8 +36,8 @@ export class Store {
35
36
  * {@link /store/inventory}
36
37
  */
37
38
  async getInventory(config: Partial<RequestConfig> & { client?: Client } = {}) {
38
- const { client: request = this.#client, ...requestConfig } = config
39
- const res = await request<GetInventoryQueryResponse, ResponseErrorConfig<Error>, unknown>({ method: 'GET', url: `/store/inventory`, ...requestConfig })
39
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
40
+ const res = await request<GetInventoryQueryResponse, ResponseErrorConfig<Error>, unknown>({ ...requestConfig, method: 'GET', url: `/store/inventory` })
40
41
  return res.data
41
42
  }
42
43
 
@@ -46,13 +47,13 @@ export class Store {
46
47
  * {@link /store/order}
47
48
  */
48
49
  async placeOrder(data?: PlaceOrderMutationRequest, config: Partial<RequestConfig<PlaceOrderMutationRequest>> & { client?: Client } = {}) {
49
- const { client: request = this.#client, ...requestConfig } = config
50
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
50
51
  const requestData = data
51
52
  const res = await request<PlaceOrderMutationResponse, ResponseErrorConfig<PlaceOrder405>, PlaceOrderMutationRequest>({
53
+ ...requestConfig,
52
54
  method: 'POST',
53
55
  url: `/store/order`,
54
56
  data: requestData,
55
- ...requestConfig,
56
57
  })
57
58
  return res.data
58
59
  }
@@ -63,13 +64,13 @@ export class Store {
63
64
  * {@link /store/order}
64
65
  */
65
66
  async placeOrderPatch(data?: PlaceOrderPatchMutationRequest, config: Partial<RequestConfig<PlaceOrderPatchMutationRequest>> & { client?: Client } = {}) {
66
- const { client: request = this.#client, ...requestConfig } = config
67
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
67
68
  const requestData = data
68
69
  const res = await request<PlaceOrderPatchMutationResponse, ResponseErrorConfig<PlaceOrderPatch405>, PlaceOrderPatchMutationRequest>({
70
+ ...requestConfig,
69
71
  method: 'PATCH',
70
72
  url: `/store/order`,
71
73
  data: requestData,
72
- ...requestConfig,
73
74
  })
74
75
  return res.data
75
76
  }
@@ -80,11 +81,11 @@ export class Store {
80
81
  * {@link /store/order/:orderId}
81
82
  */
82
83
  async getOrderById(orderId: GetOrderByIdPathParams['orderId'], config: Partial<RequestConfig> & { client?: Client } = {}) {
83
- const { client: request = this.#client, ...requestConfig } = config
84
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
84
85
  const res = await request<GetOrderByIdQueryResponse, ResponseErrorConfig<GetOrderById400 | GetOrderById404>, unknown>({
86
+ ...requestConfig,
85
87
  method: 'GET',
86
88
  url: `/store/order/${orderId}`,
87
- ...requestConfig,
88
89
  })
89
90
  return res.data
90
91
  }
@@ -95,11 +96,11 @@ export class Store {
95
96
  * {@link /store/order/:orderId}
96
97
  */
97
98
  async deleteOrder(orderId: DeleteOrderPathParams['orderId'], config: Partial<RequestConfig> & { client?: Client } = {}) {
98
- const { client: request = this.#client, ...requestConfig } = config
99
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
99
100
  const res = await request<DeleteOrderMutationResponse, ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>, unknown>({
101
+ ...requestConfig,
100
102
  method: 'DELETE',
101
103
  url: `/store/order/${orderId}`,
102
- ...requestConfig,
103
104
  })
104
105
  return res.data
105
106
  }
@@ -2,6 +2,7 @@
2
2
  * Generated by Kubb (https://kubb.dev/).
3
3
  * Do not edit manually.
4
4
  */
5
+ import fetch from './test/.kubb/fetch'
5
6
  import type { Client, RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
6
7
  import type {
7
8
  CreateUserMutationRequest,
@@ -24,13 +25,13 @@ import type {
24
25
  DeleteUser400,
25
26
  DeleteUser404,
26
27
  } from './findByTags'
27
- import { fetch } from './test/.kubb/fetch'
28
+ import { mergeConfig } from './test/.kubb/fetch'
28
29
 
29
30
  export class User {
30
- #client: Client
31
+ #config: Partial<RequestConfig> & { client?: Client }
31
32
 
32
33
  constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
33
- this.#client = config.client || fetch
34
+ this.#config = config
34
35
  }
35
36
 
36
37
  /**
@@ -39,13 +40,13 @@ export class User {
39
40
  * {@link /user}
40
41
  */
41
42
  async createUser(data?: CreateUserMutationRequest, config: Partial<RequestConfig<CreateUserMutationRequest>> & { client?: Client } = {}) {
42
- const { client: request = this.#client, ...requestConfig } = config
43
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
43
44
  const requestData = data
44
45
  const res = await request<CreateUserMutationResponse, ResponseErrorConfig<Error>, CreateUserMutationRequest>({
46
+ ...requestConfig,
45
47
  method: 'POST',
46
48
  url: `/user`,
47
49
  data: requestData,
48
- ...requestConfig,
49
50
  })
50
51
  return res.data
51
52
  }
@@ -59,13 +60,13 @@ export class User {
59
60
  data?: CreateUsersWithListInputMutationRequest,
60
61
  config: Partial<RequestConfig<CreateUsersWithListInputMutationRequest>> & { client?: Client } = {},
61
62
  ) {
62
- const { client: request = this.#client, ...requestConfig } = config
63
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
63
64
  const requestData = data
64
65
  const res = await request<CreateUsersWithListInputMutationResponse, ResponseErrorConfig<Error>, CreateUsersWithListInputMutationRequest>({
66
+ ...requestConfig,
65
67
  method: 'POST',
66
68
  url: `/user/createWithList`,
67
69
  data: requestData,
68
- ...requestConfig,
69
70
  })
70
71
  return res.data
71
72
  }
@@ -75,12 +76,12 @@ export class User {
75
76
  * {@link /user/login}
76
77
  */
77
78
  async loginUser(params?: LoginUserQueryParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
78
- const { client: request = this.#client, ...requestConfig } = config
79
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
79
80
  const res = await request<LoginUserQueryResponse, ResponseErrorConfig<LoginUser400>, unknown>({
81
+ ...requestConfig,
80
82
  method: 'GET',
81
83
  url: `/user/login`,
82
84
  params,
83
- ...requestConfig,
84
85
  })
85
86
  return res.data
86
87
  }
@@ -90,8 +91,8 @@ export class User {
90
91
  * {@link /user/logout}
91
92
  */
92
93
  async logoutUser(config: Partial<RequestConfig> & { client?: Client } = {}) {
93
- const { client: request = this.#client, ...requestConfig } = config
94
- const res = await request<LogoutUserQueryResponse, ResponseErrorConfig<Error>, unknown>({ method: 'GET', url: `/user/logout`, ...requestConfig })
94
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
95
+ const res = await request<LogoutUserQueryResponse, ResponseErrorConfig<Error>, unknown>({ ...requestConfig, method: 'GET', url: `/user/logout` })
95
96
  return res.data
96
97
  }
97
98
 
@@ -100,11 +101,11 @@ export class User {
100
101
  * {@link /user/:username}
101
102
  */
102
103
  async getUserByName(username: GetUserByNamePathParams['username'], config: Partial<RequestConfig> & { client?: Client } = {}) {
103
- const { client: request = this.#client, ...requestConfig } = config
104
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
104
105
  const res = await request<GetUserByNameQueryResponse, ResponseErrorConfig<GetUserByName400 | GetUserByName404>, unknown>({
106
+ ...requestConfig,
105
107
  method: 'GET',
106
108
  url: `/user/${username}`,
107
- ...requestConfig,
108
109
  })
109
110
  return res.data
110
111
  }
@@ -119,13 +120,13 @@ export class User {
119
120
  data?: UpdateUserMutationRequest,
120
121
  config: Partial<RequestConfig<UpdateUserMutationRequest>> & { client?: Client } = {},
121
122
  ) {
122
- const { client: request = this.#client, ...requestConfig } = config
123
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
123
124
  const requestData = data
124
125
  const res = await request<UpdateUserMutationResponse, ResponseErrorConfig<Error>, UpdateUserMutationRequest>({
126
+ ...requestConfig,
125
127
  method: 'PUT',
126
128
  url: `/user/${username}`,
127
129
  data: requestData,
128
- ...requestConfig,
129
130
  })
130
131
  return res.data
131
132
  }
@@ -136,11 +137,11 @@ export class User {
136
137
  * {@link /user/:username}
137
138
  */
138
139
  async deleteUser(username: DeleteUserPathParams['username'], config: Partial<RequestConfig> & { client?: Client } = {}) {
139
- const { client: request = this.#client, ...requestConfig } = config
140
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
140
141
  const res = await request<DeleteUserMutationResponse, ResponseErrorConfig<DeleteUser400 | DeleteUser404>, unknown>({
142
+ ...requestConfig,
141
143
  method: 'DELETE',
142
144
  url: `/user/${username}`,
143
- ...requestConfig,
144
145
  })
145
146
  return res.data
146
147
  }
@@ -2,6 +2,7 @@
2
2
  * Generated by Kubb (https://kubb.dev/).
3
3
  * Do not edit manually.
4
4
  */
5
+ import fetch from './test/.kubb/fetch'
5
6
  import type { Client, RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
6
7
  import type {
7
8
  UpdatePetMutationRequest,
@@ -36,10 +37,10 @@ import type {
36
37
  UploadFileQueryParams,
37
38
  } from './findByTags'
38
39
  import { buildFormData } from './test/.kubb/config'
39
- import { fetch } from './test/.kubb/fetch'
40
+ import { mergeConfig } from './test/.kubb/fetch'
40
41
 
41
42
  export class Pet {
42
- static #client: Client = fetch
43
+ static #config: Partial<RequestConfig> & { client?: Client } = {}
43
44
 
44
45
  /**
45
46
  * @description Update an existing pet by Id
@@ -47,13 +48,13 @@ export class Pet {
47
48
  * {@link /pet}
48
49
  */
49
50
  static async updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> & { client?: Client } = {}) {
50
- const { client: request = this.#client, ...requestConfig } = config
51
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
51
52
  const requestData = data
52
53
  const res = await request<UpdatePetMutationResponse, ResponseErrorConfig<UpdatePet400 | UpdatePet404 | UpdatePet405>, UpdatePetMutationRequest>({
54
+ ...requestConfig,
53
55
  method: 'PUT',
54
56
  url: `/pet`,
55
57
  data: requestData,
56
- ...requestConfig,
57
58
  })
58
59
  return res.data
59
60
  }
@@ -64,13 +65,13 @@ export class Pet {
64
65
  * {@link /pet}
65
66
  */
66
67
  static async addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> & { client?: Client } = {}) {
67
- const { client: request = this.#client, ...requestConfig } = config
68
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
68
69
  const requestData = data
69
70
  const res = await request<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, AddPetMutationRequest>({
71
+ ...requestConfig,
70
72
  method: 'POST',
71
73
  url: `/pet`,
72
74
  data: requestData,
73
- ...requestConfig,
74
75
  })
75
76
  return res.data
76
77
  }
@@ -81,12 +82,12 @@ export class Pet {
81
82
  * {@link /pet/findByStatus}
82
83
  */
83
84
  static async findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
84
- const { client: request = this.#client, ...requestConfig } = config
85
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
85
86
  const res = await request<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, unknown>({
87
+ ...requestConfig,
86
88
  method: 'GET',
87
89
  url: `/pet/findByStatus`,
88
90
  params,
89
- ...requestConfig,
90
91
  })
91
92
  return res.data
92
93
  }
@@ -97,12 +98,12 @@ export class Pet {
97
98
  * {@link /pet/findByTags}
98
99
  */
99
100
  static async findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
100
- const { client: request = this.#client, ...requestConfig } = config
101
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
101
102
  const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
103
+ ...requestConfig,
102
104
  method: 'GET',
103
105
  url: `/pet/findByTags`,
104
106
  params,
105
- ...requestConfig,
106
107
  })
107
108
  return res.data
108
109
  }
@@ -113,11 +114,11 @@ export class Pet {
113
114
  * {@link /pet/:petId}
114
115
  */
115
116
  static async getPetById(petId: GetPetByIdPathParams['petId'], config: Partial<RequestConfig> & { client?: Client } = {}) {
116
- const { client: request = this.#client, ...requestConfig } = config
117
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
117
118
  const res = await request<GetPetByIdQueryResponse, ResponseErrorConfig<GetPetById400 | GetPetById404>, unknown>({
119
+ ...requestConfig,
118
120
  method: 'GET',
119
121
  url: `/pet/${petId}`,
120
- ...requestConfig,
121
122
  })
122
123
  return res.data
123
124
  }
@@ -131,12 +132,12 @@ export class Pet {
131
132
  params?: UpdatePetWithFormQueryParams,
132
133
  config: Partial<RequestConfig> & { client?: Client } = {},
133
134
  ) {
134
- const { client: request = this.#client, ...requestConfig } = config
135
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
135
136
  const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, unknown>({
137
+ ...requestConfig,
136
138
  method: 'POST',
137
139
  url: `/pet/${petId}`,
138
140
  params,
139
- ...requestConfig,
140
141
  })
141
142
  return res.data
142
143
  }
@@ -147,11 +148,11 @@ export class Pet {
147
148
  * {@link /pet/:petId}
148
149
  */
149
150
  static async deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> & { client?: Client } = {}) {
150
- const { client: request = this.#client, ...requestConfig } = config
151
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
151
152
  const res = await request<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
153
+ ...requestConfig,
152
154
  method: 'DELETE',
153
155
  url: `/pet/${petId}`,
154
- ...requestConfig,
155
156
  headers: { ...headers, ...requestConfig.headers },
156
157
  })
157
158
  return res.data
@@ -167,15 +168,15 @@ export class Pet {
167
168
  params?: UploadFileQueryParams,
168
169
  config: Partial<RequestConfig<UploadFileMutationRequest>> & { client?: Client } = {},
169
170
  ) {
170
- const { client: request = this.#client, ...requestConfig } = config
171
+ const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)
171
172
  const requestData = data
172
173
  const formData = buildFormData(requestData)
173
174
  const res = await request<UploadFileMutationResponse, ResponseErrorConfig<Error>, UploadFileMutationRequest>({
175
+ ...requestConfig,
174
176
  method: 'POST',
175
177
  url: `/pet/${petId}/uploadImage`,
176
178
  params,
177
179
  data: formData as FormData,
178
- ...requestConfig,
179
180
  })
180
181
  return res.data
181
182
  }