fork of hey-api/openapi-ts because I need some additional things
1// This file is auto-generated by @hey-api/openapi-ts
2
3import type { Client, Options as Options2, TDataShape } from './client';
4import { client } from './client.gen';
5import type {
6 AddPetData,
7 AddPetErrors,
8 AddPetResponses,
9 CreateUserData,
10 CreateUserErrors,
11 CreateUserResponses,
12 CreateUsersWithListInputData,
13 CreateUsersWithListInputErrors,
14 CreateUsersWithListInputResponses,
15 DeleteOrderData,
16 DeleteOrderErrors,
17 DeleteOrderResponses,
18 DeletePetData,
19 DeletePetErrors,
20 DeletePetResponses,
21 DeleteUserData,
22 DeleteUserErrors,
23 DeleteUserResponses,
24 FindPetsByStatusData,
25 FindPetsByStatusErrors,
26 FindPetsByStatusResponses,
27 FindPetsByTagsData,
28 FindPetsByTagsErrors,
29 FindPetsByTagsResponses,
30 GetInventoryData,
31 GetInventoryErrors,
32 GetInventoryResponses,
33 GetOrderByIdData,
34 GetOrderByIdErrors,
35 GetOrderByIdResponses,
36 GetPetByIdData,
37 GetPetByIdErrors,
38 GetPetByIdResponses,
39 GetUserByNameData,
40 GetUserByNameErrors,
41 GetUserByNameResponses,
42 LoginUserData,
43 LoginUserErrors,
44 LoginUserResponses,
45 LogoutUserData,
46 LogoutUserErrors,
47 LogoutUserResponses,
48 PlaceOrderData,
49 PlaceOrderErrors,
50 PlaceOrderResponses,
51 UpdatePetData,
52 UpdatePetErrors,
53 UpdatePetResponses,
54 UpdatePetWithFormData,
55 UpdatePetWithFormErrors,
56 UpdatePetWithFormResponses,
57 UpdateUserData,
58 UpdateUserErrors,
59 UpdateUserResponses,
60 UploadFileData,
61 UploadFileErrors,
62 UploadFileResponses,
63} from './types.gen';
64
65export type Options<
66 TData extends TDataShape = TDataShape,
67 ThrowOnError extends boolean = boolean,
68> = Options2<TData, ThrowOnError> & {
69 /**
70 * You can provide a client instance returned by `createClient()` instead of
71 * individual options. This might be also useful if you want to implement a
72 * custom client.
73 */
74 client?: Client;
75 /**
76 * You can pass arbitrary values through the `meta` object. This can be
77 * used to access values that aren't defined as part of the SDK function.
78 */
79 meta?: Record<string, unknown>;
80};
81
82class HeyApiClient {
83 protected client: Client;
84
85 constructor(args?: { client?: Client }) {
86 this.client = args?.client ?? client;
87 }
88}
89
90class HeyApiRegistry<T> {
91 private readonly defaultKey = 'default';
92
93 private readonly instances: Map<string, T> = new Map();
94
95 get(key?: string): T {
96 const instance = this.instances.get(key ?? this.defaultKey);
97 if (!instance) {
98 throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`);
99 }
100 return instance;
101 }
102
103 set(value: T, key?: string): void {
104 this.instances.set(key ?? this.defaultKey, value);
105 }
106}
107
108export class Sdk extends HeyApiClient {
109 public static readonly __registry = new HeyApiRegistry<Sdk>();
110
111 constructor(args?: { client?: Client; key?: string }) {
112 super(args);
113 Sdk.__registry.set(this, args?.key);
114 }
115
116 /**
117 * Add a new pet to the store.
118 *
119 * Add a new pet to the store.
120 */
121 public addPet<ThrowOnError extends boolean = false>(options: Options<AddPetData, ThrowOnError>) {
122 return (options.client ?? this.client).post<AddPetResponses, AddPetErrors, ThrowOnError>({
123 security: [{ scheme: 'bearer', type: 'http' }],
124 url: '/pet',
125 ...options,
126 headers: {
127 'Content-Type': 'application/json',
128 ...options.headers,
129 },
130 });
131 }
132
133 /**
134 * Update an existing pet.
135 *
136 * Update an existing pet by Id.
137 */
138 public updatePet<ThrowOnError extends boolean = false>(
139 options: Options<UpdatePetData, ThrowOnError>,
140 ) {
141 return (options.client ?? this.client).put<UpdatePetResponses, UpdatePetErrors, ThrowOnError>({
142 security: [{ scheme: 'bearer', type: 'http' }],
143 url: '/pet',
144 ...options,
145 headers: {
146 'Content-Type': 'application/json',
147 ...options.headers,
148 },
149 });
150 }
151
152 /**
153 * Finds Pets by status.
154 *
155 * Multiple status values can be provided with comma separated strings.
156 */
157 public findPetsByStatus<ThrowOnError extends boolean = false>(
158 options: Options<FindPetsByStatusData, ThrowOnError>,
159 ) {
160 return (options.client ?? this.client).get<
161 FindPetsByStatusResponses,
162 FindPetsByStatusErrors,
163 ThrowOnError
164 >({
165 security: [{ scheme: 'bearer', type: 'http' }],
166 url: '/pet/findByStatus',
167 ...options,
168 });
169 }
170
171 /**
172 * Finds Pets by tags.
173 *
174 * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
175 */
176 public findPetsByTags<ThrowOnError extends boolean = false>(
177 options: Options<FindPetsByTagsData, ThrowOnError>,
178 ) {
179 return (options.client ?? this.client).get<
180 FindPetsByTagsResponses,
181 FindPetsByTagsErrors,
182 ThrowOnError
183 >({
184 security: [{ scheme: 'bearer', type: 'http' }],
185 url: '/pet/findByTags',
186 ...options,
187 });
188 }
189
190 /**
191 * Deletes a pet.
192 *
193 * Delete a pet.
194 */
195 public deletePet<ThrowOnError extends boolean = false>(
196 options: Options<DeletePetData, ThrowOnError>,
197 ) {
198 return (options.client ?? this.client).delete<
199 DeletePetResponses,
200 DeletePetErrors,
201 ThrowOnError
202 >({
203 security: [{ scheme: 'bearer', type: 'http' }],
204 url: '/pet/{petId}',
205 ...options,
206 });
207 }
208
209 /**
210 * Find pet by ID.
211 *
212 * Returns a single pet.
213 */
214 public getPetById<ThrowOnError extends boolean = false>(
215 options: Options<GetPetByIdData, ThrowOnError>,
216 ) {
217 return (options.client ?? this.client).get<GetPetByIdResponses, GetPetByIdErrors, ThrowOnError>(
218 {
219 security: [
220 { name: 'api_key', type: 'apiKey' },
221 { scheme: 'bearer', type: 'http' },
222 ],
223 url: '/pet/{petId}',
224 ...options,
225 },
226 );
227 }
228
229 /**
230 * Updates a pet in the store with form data.
231 *
232 * Updates a pet resource based on the form data.
233 */
234 public updatePetWithForm<ThrowOnError extends boolean = false>(
235 options: Options<UpdatePetWithFormData, ThrowOnError>,
236 ) {
237 return (options.client ?? this.client).post<
238 UpdatePetWithFormResponses,
239 UpdatePetWithFormErrors,
240 ThrowOnError
241 >({
242 security: [{ scheme: 'bearer', type: 'http' }],
243 url: '/pet/{petId}',
244 ...options,
245 });
246 }
247
248 /**
249 * Uploads an image.
250 *
251 * Upload image of the pet.
252 */
253 public uploadFile<ThrowOnError extends boolean = false>(
254 options: Options<UploadFileData, ThrowOnError>,
255 ) {
256 return (options.client ?? this.client).post<
257 UploadFileResponses,
258 UploadFileErrors,
259 ThrowOnError
260 >({
261 bodySerializer: null,
262 security: [{ scheme: 'bearer', type: 'http' }],
263 url: '/pet/{petId}/uploadImage',
264 ...options,
265 headers: {
266 'Content-Type': 'application/octet-stream',
267 ...options.headers,
268 },
269 });
270 }
271
272 /**
273 * Returns pet inventories by status.
274 *
275 * Returns a map of status codes to quantities.
276 */
277 public getInventory<ThrowOnError extends boolean = false>(
278 options?: Options<GetInventoryData, ThrowOnError>,
279 ) {
280 return (options?.client ?? this.client).get<
281 GetInventoryResponses,
282 GetInventoryErrors,
283 ThrowOnError
284 >({
285 security: [{ name: 'api_key', type: 'apiKey' }],
286 url: '/store/inventory',
287 ...options,
288 });
289 }
290
291 /**
292 * Place an order for a pet.
293 *
294 * Place a new order in the store.
295 */
296 public placeOrder<ThrowOnError extends boolean = false>(
297 options?: Options<PlaceOrderData, ThrowOnError>,
298 ) {
299 return (options?.client ?? this.client).post<
300 PlaceOrderResponses,
301 PlaceOrderErrors,
302 ThrowOnError
303 >({
304 url: '/store/order',
305 ...options,
306 headers: {
307 'Content-Type': 'application/json',
308 ...options?.headers,
309 },
310 });
311 }
312
313 /**
314 * Delete purchase order by identifier.
315 *
316 * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors.
317 */
318 public deleteOrder<ThrowOnError extends boolean = false>(
319 options: Options<DeleteOrderData, ThrowOnError>,
320 ) {
321 return (options.client ?? this.client).delete<
322 DeleteOrderResponses,
323 DeleteOrderErrors,
324 ThrowOnError
325 >({ url: '/store/order/{orderId}', ...options });
326 }
327
328 /**
329 * Find purchase order by ID.
330 *
331 * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
332 */
333 public getOrderById<ThrowOnError extends boolean = false>(
334 options: Options<GetOrderByIdData, ThrowOnError>,
335 ) {
336 return (options.client ?? this.client).get<
337 GetOrderByIdResponses,
338 GetOrderByIdErrors,
339 ThrowOnError
340 >({ url: '/store/order/{orderId}', ...options });
341 }
342
343 /**
344 * Create user.
345 *
346 * This can only be done by the logged in user.
347 */
348 public createUser<ThrowOnError extends boolean = false>(
349 options?: Options<CreateUserData, ThrowOnError>,
350 ) {
351 return (options?.client ?? this.client).post<
352 CreateUserResponses,
353 CreateUserErrors,
354 ThrowOnError
355 >({
356 url: '/user',
357 ...options,
358 headers: {
359 'Content-Type': 'application/json',
360 ...options?.headers,
361 },
362 });
363 }
364
365 /**
366 * Creates list of users with given input array.
367 *
368 * Creates list of users with given input array.
369 */
370 public createUsersWithListInput<ThrowOnError extends boolean = false>(
371 options?: Options<CreateUsersWithListInputData, ThrowOnError>,
372 ) {
373 return (options?.client ?? this.client).post<
374 CreateUsersWithListInputResponses,
375 CreateUsersWithListInputErrors,
376 ThrowOnError
377 >({
378 url: '/user/createWithList',
379 ...options,
380 headers: {
381 'Content-Type': 'application/json',
382 ...options?.headers,
383 },
384 });
385 }
386
387 /**
388 * Logs user into the system.
389 *
390 * Log into the system.
391 */
392 public loginUser<ThrowOnError extends boolean = false>(
393 options?: Options<LoginUserData, ThrowOnError>,
394 ) {
395 return (options?.client ?? this.client).get<LoginUserResponses, LoginUserErrors, ThrowOnError>({
396 url: '/user/login',
397 ...options,
398 });
399 }
400
401 /**
402 * Logs out current logged in user session.
403 *
404 * Log user out of the system.
405 */
406 public logoutUser<ThrowOnError extends boolean = false>(
407 options?: Options<LogoutUserData, ThrowOnError>,
408 ) {
409 return (options?.client ?? this.client).get<
410 LogoutUserResponses,
411 LogoutUserErrors,
412 ThrowOnError
413 >({ url: '/user/logout', ...options });
414 }
415
416 /**
417 * Delete user resource.
418 *
419 * This can only be done by the logged in user.
420 */
421 public deleteUser<ThrowOnError extends boolean = false>(
422 options: Options<DeleteUserData, ThrowOnError>,
423 ) {
424 return (options.client ?? this.client).delete<
425 DeleteUserResponses,
426 DeleteUserErrors,
427 ThrowOnError
428 >({ url: '/user/{username}', ...options });
429 }
430
431 /**
432 * Get user by user name.
433 *
434 * Get user detail based on username.
435 */
436 public getUserByName<ThrowOnError extends boolean = false>(
437 options: Options<GetUserByNameData, ThrowOnError>,
438 ) {
439 return (options.client ?? this.client).get<
440 GetUserByNameResponses,
441 GetUserByNameErrors,
442 ThrowOnError
443 >({ url: '/user/{username}', ...options });
444 }
445
446 /**
447 * Update user resource.
448 *
449 * This can only be done by the logged in user.
450 */
451 public updateUser<ThrowOnError extends boolean = false>(
452 options: Options<UpdateUserData, ThrowOnError>,
453 ) {
454 return (options.client ?? this.client).put<UpdateUserResponses, UpdateUserErrors, ThrowOnError>(
455 {
456 url: '/user/{username}',
457 ...options,
458 headers: {
459 'Content-Type': 'application/json',
460 ...options.headers,
461 },
462 },
463 );
464 }
465}