fork of hey-api/openapi-ts because I need some additional things
at main 482 lines 12 kB view raw
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( 99 `No SDK client found. Create one with "new Sdk()" to fix this error.`, 100 ); 101 } 102 return instance; 103 } 104 105 set(value: T, key?: string): void { 106 this.instances.set(key ?? this.defaultKey, value); 107 } 108} 109 110export class Sdk extends HeyApiClient { 111 public static readonly __registry = new HeyApiRegistry<Sdk>(); 112 113 constructor(args?: { client?: Client; key?: string }) { 114 super(args); 115 Sdk.__registry.set(this, args?.key); 116 } 117 118 /** 119 * Add a new pet to the store. 120 * 121 * Add a new pet to the store. 122 */ 123 public addPet<ThrowOnError extends boolean = false>( 124 options: Options<AddPetData, ThrowOnError>, 125 ) { 126 return (options.client ?? this.client).post< 127 AddPetResponses, 128 AddPetErrors, 129 ThrowOnError 130 >({ 131 security: [{ scheme: 'bearer', type: 'http' }], 132 url: '/pet', 133 ...options, 134 headers: { 135 'Content-Type': 'application/json', 136 ...options.headers, 137 }, 138 }); 139 } 140 141 /** 142 * Update an existing pet. 143 * 144 * Update an existing pet by Id. 145 */ 146 public updatePet<ThrowOnError extends boolean = false>( 147 options: Options<UpdatePetData, ThrowOnError>, 148 ) { 149 return (options.client ?? this.client).put< 150 UpdatePetResponses, 151 UpdatePetErrors, 152 ThrowOnError 153 >({ 154 security: [{ scheme: 'bearer', type: 'http' }], 155 url: '/pet', 156 ...options, 157 headers: { 158 'Content-Type': 'application/json', 159 ...options.headers, 160 }, 161 }); 162 } 163 164 /** 165 * Finds Pets by status. 166 * 167 * Multiple status values can be provided with comma separated strings. 168 */ 169 public findPetsByStatus<ThrowOnError extends boolean = false>( 170 options: Options<FindPetsByStatusData, ThrowOnError>, 171 ) { 172 return (options.client ?? this.client).get< 173 FindPetsByStatusResponses, 174 FindPetsByStatusErrors, 175 ThrowOnError 176 >({ 177 security: [{ scheme: 'bearer', type: 'http' }], 178 url: '/pet/findByStatus', 179 ...options, 180 }); 181 } 182 183 /** 184 * Finds Pets by tags. 185 * 186 * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. 187 */ 188 public findPetsByTags<ThrowOnError extends boolean = false>( 189 options: Options<FindPetsByTagsData, ThrowOnError>, 190 ) { 191 return (options.client ?? this.client).get< 192 FindPetsByTagsResponses, 193 FindPetsByTagsErrors, 194 ThrowOnError 195 >({ 196 security: [{ scheme: 'bearer', type: 'http' }], 197 url: '/pet/findByTags', 198 ...options, 199 }); 200 } 201 202 /** 203 * Deletes a pet. 204 * 205 * Delete a pet. 206 */ 207 public deletePet<ThrowOnError extends boolean = false>( 208 options: Options<DeletePetData, ThrowOnError>, 209 ) { 210 return (options.client ?? this.client).delete< 211 DeletePetResponses, 212 DeletePetErrors, 213 ThrowOnError 214 >({ 215 security: [{ scheme: 'bearer', type: 'http' }], 216 url: '/pet/{petId}', 217 ...options, 218 }); 219 } 220 221 /** 222 * Find pet by ID. 223 * 224 * Returns a single pet. 225 */ 226 public getPetById<ThrowOnError extends boolean = false>( 227 options: Options<GetPetByIdData, ThrowOnError>, 228 ) { 229 return (options.client ?? this.client).get< 230 GetPetByIdResponses, 231 GetPetByIdErrors, 232 ThrowOnError 233 >({ 234 security: [ 235 { name: 'api_key', type: 'apiKey' }, 236 { scheme: 'bearer', type: 'http' }, 237 ], 238 url: '/pet/{petId}', 239 ...options, 240 }); 241 } 242 243 /** 244 * Updates a pet in the store with form data. 245 * 246 * Updates a pet resource based on the form data. 247 */ 248 public updatePetWithForm<ThrowOnError extends boolean = false>( 249 options: Options<UpdatePetWithFormData, ThrowOnError>, 250 ) { 251 return (options.client ?? this.client).post< 252 UpdatePetWithFormResponses, 253 UpdatePetWithFormErrors, 254 ThrowOnError 255 >({ 256 security: [{ scheme: 'bearer', type: 'http' }], 257 url: '/pet/{petId}', 258 ...options, 259 }); 260 } 261 262 /** 263 * Uploads an image. 264 * 265 * Upload image of the pet. 266 */ 267 public uploadFile<ThrowOnError extends boolean = false>( 268 options: Options<UploadFileData, ThrowOnError>, 269 ) { 270 return (options.client ?? this.client).post< 271 UploadFileResponses, 272 UploadFileErrors, 273 ThrowOnError 274 >({ 275 bodySerializer: null, 276 security: [{ scheme: 'bearer', type: 'http' }], 277 url: '/pet/{petId}/uploadImage', 278 ...options, 279 headers: { 280 'Content-Type': 'application/octet-stream', 281 ...options.headers, 282 }, 283 }); 284 } 285 286 /** 287 * Returns pet inventories by status. 288 * 289 * Returns a map of status codes to quantities. 290 */ 291 public getInventory<ThrowOnError extends boolean = false>( 292 options?: Options<GetInventoryData, ThrowOnError>, 293 ) { 294 return (options?.client ?? this.client).get< 295 GetInventoryResponses, 296 GetInventoryErrors, 297 ThrowOnError 298 >({ 299 security: [{ name: 'api_key', type: 'apiKey' }], 300 url: '/store/inventory', 301 ...options, 302 }); 303 } 304 305 /** 306 * Place an order for a pet. 307 * 308 * Place a new order in the store. 309 */ 310 public placeOrder<ThrowOnError extends boolean = false>( 311 options?: Options<PlaceOrderData, ThrowOnError>, 312 ) { 313 return (options?.client ?? this.client).post< 314 PlaceOrderResponses, 315 PlaceOrderErrors, 316 ThrowOnError 317 >({ 318 url: '/store/order', 319 ...options, 320 headers: { 321 'Content-Type': 'application/json', 322 ...options?.headers, 323 }, 324 }); 325 } 326 327 /** 328 * Delete purchase order by identifier. 329 * 330 * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors. 331 */ 332 public deleteOrder<ThrowOnError extends boolean = false>( 333 options: Options<DeleteOrderData, ThrowOnError>, 334 ) { 335 return (options.client ?? this.client).delete< 336 DeleteOrderResponses, 337 DeleteOrderErrors, 338 ThrowOnError 339 >({ url: '/store/order/{orderId}', ...options }); 340 } 341 342 /** 343 * Find purchase order by ID. 344 * 345 * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. 346 */ 347 public getOrderById<ThrowOnError extends boolean = false>( 348 options: Options<GetOrderByIdData, ThrowOnError>, 349 ) { 350 return (options.client ?? this.client).get< 351 GetOrderByIdResponses, 352 GetOrderByIdErrors, 353 ThrowOnError 354 >({ url: '/store/order/{orderId}', ...options }); 355 } 356 357 /** 358 * Create user. 359 * 360 * This can only be done by the logged in user. 361 */ 362 public createUser<ThrowOnError extends boolean = false>( 363 options?: Options<CreateUserData, ThrowOnError>, 364 ) { 365 return (options?.client ?? this.client).post< 366 CreateUserResponses, 367 CreateUserErrors, 368 ThrowOnError 369 >({ 370 url: '/user', 371 ...options, 372 headers: { 373 'Content-Type': 'application/json', 374 ...options?.headers, 375 }, 376 }); 377 } 378 379 /** 380 * Creates list of users with given input array. 381 * 382 * Creates list of users with given input array. 383 */ 384 public createUsersWithListInput<ThrowOnError extends boolean = false>( 385 options?: Options<CreateUsersWithListInputData, ThrowOnError>, 386 ) { 387 return (options?.client ?? this.client).post< 388 CreateUsersWithListInputResponses, 389 CreateUsersWithListInputErrors, 390 ThrowOnError 391 >({ 392 url: '/user/createWithList', 393 ...options, 394 headers: { 395 'Content-Type': 'application/json', 396 ...options?.headers, 397 }, 398 }); 399 } 400 401 /** 402 * Logs user into the system. 403 * 404 * Log into the system. 405 */ 406 public loginUser<ThrowOnError extends boolean = false>( 407 options?: Options<LoginUserData, ThrowOnError>, 408 ) { 409 return (options?.client ?? this.client).get< 410 LoginUserResponses, 411 LoginUserErrors, 412 ThrowOnError 413 >({ url: '/user/login', ...options }); 414 } 415 416 /** 417 * Logs out current logged in user session. 418 * 419 * Log user out of the system. 420 */ 421 public logoutUser<ThrowOnError extends boolean = false>( 422 options?: Options<LogoutUserData, ThrowOnError>, 423 ) { 424 return (options?.client ?? this.client).get< 425 LogoutUserResponses, 426 LogoutUserErrors, 427 ThrowOnError 428 >({ url: '/user/logout', ...options }); 429 } 430 431 /** 432 * Delete user resource. 433 * 434 * This can only be done by the logged in user. 435 */ 436 public deleteUser<ThrowOnError extends boolean = false>( 437 options: Options<DeleteUserData, ThrowOnError>, 438 ) { 439 return (options.client ?? this.client).delete< 440 DeleteUserResponses, 441 DeleteUserErrors, 442 ThrowOnError 443 >({ url: '/user/{username}', ...options }); 444 } 445 446 /** 447 * Get user by user name. 448 * 449 * Get user detail based on username. 450 */ 451 public getUserByName<ThrowOnError extends boolean = false>( 452 options: Options<GetUserByNameData, ThrowOnError>, 453 ) { 454 return (options.client ?? this.client).get< 455 GetUserByNameResponses, 456 GetUserByNameErrors, 457 ThrowOnError 458 >({ url: '/user/{username}', ...options }); 459 } 460 461 /** 462 * Update user resource. 463 * 464 * This can only be done by the logged in user. 465 */ 466 public updateUser<ThrowOnError extends boolean = false>( 467 options: Options<UpdateUserData, ThrowOnError>, 468 ) { 469 return (options.client ?? this.client).put< 470 UpdateUserResponses, 471 UpdateUserErrors, 472 ThrowOnError 473 >({ 474 url: '/user/{username}', 475 ...options, 476 headers: { 477 'Content-Type': 'application/json', 478 ...options.headers, 479 }, 480 }); 481 } 482}