fork of hey-api/openapi-ts because I need some additional things

Merge pull request #890 from hey-api/chore/tanstack-query-wip-4

chore: progress on TanStack Query plugin

authored by

Lubos and committed by
GitHub
f29d83ad 8725bf54

+456 -576
+1
packages/openapi-ts/src/compiler/index.ts
··· 155 155 expressionToStatement: convert.expressionToStatement, 156 156 identifier: utils.createIdentifier, 157 157 ifStatement: transform.createIfStatement, 158 + indexedAccessTypeNode: types.createIndexedAccessTypeNode, 158 159 isTsNode: utils.isTsNode, 159 160 keywordTypeNode: types.createKeywordTypeNode, 160 161 methodDeclaration: classes.createMethodDeclaration,
+7 -3
packages/openapi-ts/src/compiler/module.ts
··· 104 104 comment, 105 105 constAssertion, 106 106 destructure, 107 - expression, 108 107 exportConst, 108 + expression, 109 109 name, 110 110 typeName, 111 111 }: { ··· 116 116 expression: ts.Expression; 117 117 name: string; 118 118 // TODO: support a more intuitive definition of generics for example 119 - typeName?: string; 119 + typeName?: string | ts.IndexedAccessTypeNode; 120 120 }): ts.VariableStatement => { 121 121 const initializer = constAssertion 122 122 ? ts.factory.createAsExpression( ··· 137 137 ]) 138 138 : nameIdentifier, 139 139 undefined, 140 - typeName ? ts.factory.createTypeReferenceNode(typeName) : undefined, 140 + typeName 141 + ? typeof typeName === 'string' 142 + ? ts.factory.createTypeReferenceNode(typeName) 143 + : typeName 144 + : undefined, 141 145 initializer, 142 146 ); 143 147 const statement = ts.factory.createVariableStatement(
+32 -9
packages/openapi-ts/src/compiler/types.ts
··· 33 33 34 34 export const createPropertyAccessExpression = ({ 35 35 expression, 36 + isOptional, 36 37 name, 37 38 }: { 38 39 expression: string | ts.Expression; 40 + isOptional?: boolean; 39 41 name: string | ts.MemberName; 40 42 }) => { 41 - const node = ts.factory.createPropertyAccessExpression( 43 + const nodeExpression = 42 44 typeof expression === 'string' 43 45 ? createIdentifier({ text: expression }) 44 - : expression, 45 - typeof name === 'string' ? createIdentifier({ text: name }) : name, 46 + : expression; 47 + 48 + const nodeName = 49 + typeof name === 'string' ? createIdentifier({ text: name }) : name; 50 + 51 + if (isOptional) { 52 + const node = ts.factory.createPropertyAccessChain( 53 + nodeExpression, 54 + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), 55 + nodeName, 56 + ); 57 + return node; 58 + } 59 + 60 + const node = ts.factory.createPropertyAccessExpression( 61 + nodeExpression, 62 + nodeName, 46 63 ); 47 64 return node; 48 65 }; ··· 176 193 modifiers, 177 194 undefined, 178 195 createIdentifier({ text: parameter.name }), 179 - parameter.isRequired !== undefined && !parameter.isRequired 196 + parameter.isRequired === false 180 197 ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) 181 198 : undefined, 182 199 parameter.type !== undefined ? createTypeNode(parameter.type) : undefined, ··· 438 455 ? ts.factory.createShorthandPropertyAssignment(value) 439 456 : ts.factory.createPropertyAssignment(key, initializer); 440 457 441 - // addLeadingComments({ 442 - // comments: comments?.[key], 443 - // node: assignment, 444 - // }); 445 - 446 458 return assignment; 447 459 }) 448 460 .filter(isType<ObjectAssignment>); ··· 525 537 ts.factory.createModuleBlock(statements), 526 538 ts.NodeFlags.Namespace, 527 539 ); 540 + 541 + export const createIndexedAccessTypeNode = ({ 542 + indexType, 543 + objectType, 544 + }: { 545 + indexType: ts.TypeNode; 546 + objectType: ts.TypeNode; 547 + }) => { 548 + const node = ts.factory.createIndexedAccessTypeNode(objectType, indexType); 549 + return node; 550 + };
+222 -94
packages/openapi-ts/src/generate/plugins.ts
··· 1 1 import path from 'node:path'; 2 2 3 - import { compiler, TypeScriptFile } from '../compiler'; 3 + import ts from 'typescript'; 4 + 5 + import { compiler, Property, TypeScriptFile } from '../compiler'; 4 6 import type { ImportExportItem } from '../compiler/module'; 5 7 import type { ImportExportItemObject } from '../compiler/utils'; 6 8 import type { Operation } from '../openApi'; ··· 76 78 let imports: string[] = []; 77 79 let importsServices: ImportExportItem[] = []; 78 80 81 + const createQueryKeyParamsFn = 'createQueryKeyParams'; 79 82 const infiniteQueryOptionsFn = 'infiniteQueryOptions'; 80 83 const mutationsType = 'UseMutationOptions'; 84 + const queryKeyName = 'QueryKey'; 81 85 const queryOptionsFn = 'queryOptions'; 82 86 83 87 // TODO: `addTanStackQueryImport()` should be a method of file class to create ··· 114 118 } 115 119 }; 116 120 121 + let hasCreateQueryKeyParamsFunction = false; 122 + const createQueryKeyParamsFunction = () => { 123 + hasCreateQueryKeyParamsFunction = true; 124 + 125 + const queryKeyParamsFunction = compiler.constVariable({ 126 + expression: compiler.arrowFunction({ 127 + multiLine: true, 128 + parameters: [ 129 + { 130 + isRequired: false, 131 + name: 'options', 132 + type: compiler.typeNode('Options', [compiler.typeNode('T')]), 133 + }, 134 + ], 135 + statements: [ 136 + compiler.constVariable({ 137 + expression: compiler.objectExpression({ 138 + multiLine: false, 139 + obj: [], 140 + }), 141 + name: 'params', 142 + typeName: compiler.indexedAccessTypeNode({ 143 + indexType: ts.factory.createLiteralTypeNode( 144 + ts.factory.createStringLiteral('params'), 145 + ), 146 + objectType: compiler.indexedAccessTypeNode({ 147 + indexType: compiler.typeNode(0), 148 + objectType: compiler.typeNode('QueryKey'), 149 + }), 150 + }), 151 + }), 152 + compiler.ifStatement({ 153 + expression: compiler.propertyAccessExpression({ 154 + expression: 'options', 155 + isOptional: true, 156 + name: 'body', 157 + }), 158 + thenStatement: ts.factory.createBlock( 159 + [ 160 + compiler.expressionToStatement({ 161 + expression: compiler.binaryExpression({ 162 + left: compiler.propertyAccessExpression({ 163 + expression: 'params', 164 + name: 'body', 165 + }), 166 + right: compiler.propertyAccessExpression({ 167 + expression: 'options', 168 + name: 'body', 169 + }), 170 + }), 171 + }), 172 + ], 173 + true, 174 + ), 175 + }), 176 + compiler.ifStatement({ 177 + expression: compiler.propertyAccessExpression({ 178 + expression: 'options', 179 + isOptional: true, 180 + name: 'headers', 181 + }), 182 + thenStatement: ts.factory.createBlock( 183 + [ 184 + compiler.expressionToStatement({ 185 + expression: compiler.binaryExpression({ 186 + left: compiler.propertyAccessExpression({ 187 + expression: 'params', 188 + name: 'headers', 189 + }), 190 + right: compiler.propertyAccessExpression({ 191 + expression: 'options', 192 + name: 'headers', 193 + }), 194 + }), 195 + }), 196 + ], 197 + true, 198 + ), 199 + }), 200 + compiler.ifStatement({ 201 + expression: compiler.propertyAccessExpression({ 202 + expression: 'options', 203 + isOptional: true, 204 + name: 'path', 205 + }), 206 + thenStatement: ts.factory.createBlock( 207 + [ 208 + compiler.expressionToStatement({ 209 + expression: compiler.binaryExpression({ 210 + left: compiler.propertyAccessExpression({ 211 + expression: 'params', 212 + name: 'path', 213 + }), 214 + right: compiler.propertyAccessExpression({ 215 + expression: 'options', 216 + name: 'path', 217 + }), 218 + }), 219 + }), 220 + ], 221 + true, 222 + ), 223 + }), 224 + compiler.ifStatement({ 225 + expression: compiler.propertyAccessExpression({ 226 + expression: 'options', 227 + isOptional: true, 228 + name: 'query', 229 + }), 230 + thenStatement: ts.factory.createBlock( 231 + [ 232 + compiler.expressionToStatement({ 233 + expression: compiler.binaryExpression({ 234 + left: compiler.propertyAccessExpression({ 235 + expression: 'params', 236 + name: 'query', 237 + }), 238 + right: compiler.propertyAccessExpression({ 239 + expression: 'options', 240 + name: 'query', 241 + }), 242 + }), 243 + }), 244 + ], 245 + true, 246 + ), 247 + }), 248 + compiler.returnVariable({ 249 + name: 'params', 250 + }), 251 + ], 252 + types: [ 253 + { 254 + name: 'T', 255 + }, 256 + ], 257 + }), 258 + name: createQueryKeyParamsFn, 259 + }); 260 + files[plugin.name].add(queryKeyParamsFunction); 261 + }; 262 + 117 263 const createQueryKeyLiteral = ({ 118 264 isInfinite, 119 - isRequired, 120 265 operation, 121 266 }: { 122 267 isInfinite?: boolean; 123 - isRequired: boolean; 124 268 operation: Operation; 125 269 }) => { 126 270 const queryKeyLiteral = compiler.arrayLiteralExpression({ ··· 133 277 }, 134 278 { 135 279 key: 'params', 136 - value: compiler.objectExpression({ 137 - obj: [ 138 - { 139 - isValueAccess: true, 140 - key: 'body', 141 - value: isRequired 142 - ? 'options.body ?? {}' 143 - : 'options?.body ?? {}', 144 - }, 145 - { 146 - isValueAccess: true, 147 - key: 'headers', 148 - value: isRequired 149 - ? 'options.headers ?? {}' 150 - : 'options?.headers ?? {}', 151 - }, 152 - { 153 - isValueAccess: true, 154 - key: 'path', 155 - value: isRequired 156 - ? 'options.path ?? {}' 157 - : 'options?.path ?? {}', 158 - }, 159 - { 160 - isValueAccess: true, 161 - key: 'query', 162 - value: isRequired 163 - ? 'options.query ?? {}' 164 - : 'options?.query ?? {}', 165 - }, 166 - ], 280 + value: compiler.callExpression({ 281 + functionName: createQueryKeyParamsFn, 282 + parameters: ['options'], 167 283 }), 168 284 }, 169 285 { ··· 177 293 return queryKeyLiteral; 178 294 }; 179 295 296 + const createQueryKeyType = () => { 297 + const properties: Property[] = [ 298 + { 299 + isRequired: false, 300 + name: 'infinite', 301 + type: compiler.keywordTypeNode({ 302 + keyword: 'boolean', 303 + }), 304 + }, 305 + { 306 + name: 'params', 307 + type: compiler.typeInterfaceNode({ 308 + properties: [ 309 + { 310 + isRequired: false, 311 + name: 'body', 312 + type: compiler.keywordTypeNode({ 313 + keyword: 'any', 314 + }), 315 + }, 316 + { 317 + isRequired: false, 318 + name: 'headers', 319 + type: compiler.keywordTypeNode({ 320 + keyword: 'any', 321 + }), 322 + }, 323 + { 324 + isRequired: false, 325 + name: 'path', 326 + type: compiler.keywordTypeNode({ 327 + keyword: 'any', 328 + }), 329 + }, 330 + { 331 + isRequired: false, 332 + name: 'query', 333 + type: compiler.keywordTypeNode({ 334 + keyword: 'any', 335 + }), 336 + }, 337 + ], 338 + }), 339 + }, 340 + { 341 + name: 'scope', 342 + type: compiler.keywordTypeNode({ 343 + keyword: 'string', 344 + }), 345 + }, 346 + ]; 347 + 348 + const queryKeyType = compiler.typeAliasDeclaration({ 349 + name: queryKeyName, 350 + type: compiler.typeTupleNode({ 351 + types: [compiler.typeInterfaceNode({ properties })], 352 + }), 353 + }); 354 + files[plugin.name].add(queryKeyType); 355 + }; 356 + 180 357 let typeInfiniteData!: ImportExportItem; 181 358 let hasInfiniteQueries = false; 182 359 let hasMutations = false; ··· 197 374 if (!hasQueries) { 198 375 hasQueries = true; 199 376 377 + if (!hasCreateQueryKeyParamsFunction) { 378 + createQueryKeyType(); 379 + createQueryKeyParamsFunction(); 380 + } 381 + 200 382 addTanStackQueryImport(queryOptionsFn); 201 383 } 202 384 ··· 285 467 { 286 468 key: 'queryKey', 287 469 value: createQueryKeyLiteral({ 288 - isRequired, 289 470 operation, 290 471 }), 291 472 }, ··· 353 534 if (!hasInfiniteQueries) { 354 535 hasInfiniteQueries = true; 355 536 537 + if (!hasCreateQueryKeyParamsFunction) { 538 + createQueryKeyType(); 539 + createQueryKeyParamsFunction(); 540 + } 541 + 356 542 addTanStackQueryImport(infiniteQueryOptionsFn); 357 543 358 544 typeInfiniteData = addTanStackQueryImport({ 359 545 asType: true, 360 546 name: 'InfiniteData', 361 547 }); 362 - 363 - const queryKeyType = compiler.typeAliasDeclaration({ 364 - name: 'QueryKey', 365 - type: compiler.typeTupleNode({ 366 - types: [ 367 - compiler.typeInterfaceNode({ 368 - properties: [ 369 - { 370 - isRequired: false, 371 - name: 'infinite', 372 - type: compiler.keywordTypeNode({ 373 - keyword: 'boolean', 374 - }), 375 - }, 376 - { 377 - name: 'params', 378 - type: compiler.typeInterfaceNode({ 379 - properties: [ 380 - { 381 - name: 'body', 382 - type: compiler.keywordTypeNode({ 383 - keyword: 'any', 384 - }), 385 - }, 386 - { 387 - name: 'headers', 388 - type: compiler.keywordTypeNode({ 389 - keyword: 'any', 390 - }), 391 - }, 392 - { 393 - name: 'path', 394 - type: compiler.keywordTypeNode({ 395 - keyword: 'any', 396 - }), 397 - }, 398 - { 399 - name: 'query', 400 - type: compiler.keywordTypeNode({ 401 - keyword: 'any', 402 - }), 403 - }, 404 - ], 405 - }), 406 - }, 407 - { 408 - name: 'scope', 409 - type: compiler.keywordTypeNode({ 410 - keyword: 'string', 411 - }), 412 - }, 413 - ], 414 - }), 415 - ], 416 - }), 417 - }); 418 - files[plugin.name].add(queryKeyType); 419 548 } 420 549 421 550 hasUsedQueryFn = true; ··· 570 699 key: 'queryKey', 571 700 value: createQueryKeyLiteral({ 572 701 isInfinite: true, 573 - isRequired, 574 702 operation, 575 703 }), 576 704 }, ··· 581 709 // TODO: better types syntax 582 710 // TODO: detect pageParam type 583 711 types: [ 584 - `${typeResponse}, ${typeof typeError === 'string' ? typeError : typeError.name}, ${typeof typeInfiniteData === 'string' ? typeInfiniteData : typeInfiniteData.name}<${typeResponse}>, QueryKey, unknown`, 712 + `${typeResponse}, ${typeof typeError === 'string' ? typeError : typeError.name}, ${typeof typeInfiniteData === 'string' ? typeInfiniteData : typeInfiniteData.name}<${typeResponse}>, ${queryKeyName}, unknown`, 585 713 ], 586 714 }), 587 715 ],
+66 -229
packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-axios-plugin-tanstack-react-query/@tanstack/query.gen.ts.snap
··· 5 5 import { export_, import_, apiVVersionOdataControllerCount, getCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, postCallWithoutParametersAndResponse, deleteCallWithoutParametersAndResponse, patchCallWithoutParametersAndResponse, deleteFoo, callWithDescriptions, deprecatedCall, callWithParameters, callWithWeirdParameterNames, getCallWithOptionalParam, postCallWithOptionalParam, postApiVbyApiVersionRequestBody, postApiVbyApiVersionFormData, callWithDefaultParameters, callWithDefaultOptionalParameters, callToTestOrderOfParams, duplicateName, duplicateName1, duplicateName2, duplicateName3, callWithNoContentResponse, callWithResponseAndNoContentResponse, dummyA, dummyB, callWithResponse, callWithDuplicateResponses, callWithResponses, collectionFormat, types, uploadFile, fileResponse, complexTypes, multipartRequest, multipartResponse, complexParams, callWithResultFromHeader, testErrorCode, nonAsciiæøåÆøÅöôêÊ字符串, putWithFormUrlEncoded } from '../services.gen'; 6 6 import type { ImportData, ImportError, ImportResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsError, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from '../types.gen'; 7 7 8 + type QueryKey = [ 9 + { 10 + infinite?: boolean; 11 + params: { 12 + body?: any; 13 + headers?: any; 14 + path?: any; 15 + query?: any; 16 + }; 17 + scope: string; 18 + } 19 + ]; 20 + 21 + const createQueryKeyParams = <T>(options?: Options<T>) => { 22 + const params: QueryKey[0]["params"] = {}; 23 + if (options?.body) { 24 + params.body = options.body; 25 + } 26 + if (options?.headers) { 27 + params.headers = options.headers; 28 + } 29 + if (options?.path) { 30 + params.path = options.path; 31 + } 32 + if (options?.query) { 33 + params.query = options.query; 34 + } 35 + return params; 36 + }; 37 + 8 38 export const exportOptions = (options?: Options) => { return queryOptions({ 9 39 queryFn: async ({ queryKey }) => { 10 40 const { data } = await export_({ ··· 16 46 }, 17 47 queryKey: [ 18 48 { 19 - params: { 20 - body: options?.body ?? {}, 21 - headers: options?.headers ?? {}, 22 - path: options?.path ?? {}, 23 - query: options?.query ?? {} 24 - }, 49 + params: createQueryKeyParams(options), 25 50 scope: 'export' 26 51 } 27 52 ] ··· 38 63 }, 39 64 queryKey: [ 40 65 { 41 - params: { 42 - body: options.body ?? {}, 43 - headers: options.headers ?? {}, 44 - path: options.path ?? {}, 45 - query: options.query ?? {} 46 - }, 66 + params: createQueryKeyParams(options), 47 67 scope: 'import' 48 68 } 49 69 ] ··· 70 90 }, 71 91 queryKey: [ 72 92 { 73 - params: { 74 - body: options?.body ?? {}, 75 - headers: options?.headers ?? {}, 76 - path: options?.path ?? {}, 77 - query: options?.query ?? {} 78 - }, 93 + params: createQueryKeyParams(options), 79 94 scope: 'apiVVersionOdataControllerCount' 80 95 } 81 96 ] ··· 92 107 }, 93 108 queryKey: [ 94 109 { 95 - params: { 96 - body: options?.body ?? {}, 97 - headers: options?.headers ?? {}, 98 - path: options?.path ?? {}, 99 - query: options?.query ?? {} 100 - }, 110 + params: createQueryKeyParams(options), 101 111 scope: 'getCallWithoutParametersAndResponse' 102 112 } 103 113 ] ··· 124 134 }, 125 135 queryKey: [ 126 136 { 127 - params: { 128 - body: options?.body ?? {}, 129 - headers: options?.headers ?? {}, 130 - path: options?.path ?? {}, 131 - query: options?.query ?? {} 132 - }, 137 + params: createQueryKeyParams(options), 133 138 scope: 'postCallWithoutParametersAndResponse' 134 139 } 135 140 ] ··· 186 191 }, 187 192 queryKey: [ 188 193 { 189 - params: { 190 - body: options?.body ?? {}, 191 - headers: options?.headers ?? {}, 192 - path: options?.path ?? {}, 193 - query: options?.query ?? {} 194 - }, 194 + params: createQueryKeyParams(options), 195 195 scope: 'callWithDescriptions' 196 196 } 197 197 ] ··· 218 218 }, 219 219 queryKey: [ 220 220 { 221 - params: { 222 - body: options.body ?? {}, 223 - headers: options.headers ?? {}, 224 - path: options.path ?? {}, 225 - query: options.query ?? {} 226 - }, 221 + params: createQueryKeyParams(options), 227 222 scope: 'deprecatedCall' 228 223 } 229 224 ] ··· 250 245 }, 251 246 queryKey: [ 252 247 { 253 - params: { 254 - body: options.body ?? {}, 255 - headers: options.headers ?? {}, 256 - path: options.path ?? {}, 257 - query: options.query ?? {} 258 - }, 248 + params: createQueryKeyParams(options), 259 249 scope: 'callWithParameters' 260 250 } 261 251 ] 262 252 }); }; 263 253 264 - type QueryKey = [ 265 - { 266 - infinite?: boolean; 267 - params: { 268 - body: any; 269 - headers: any; 270 - path: any; 271 - query: any; 272 - }; 273 - scope: string; 274 - } 275 - ]; 276 - 277 254 export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey, unknown>( 278 255 // @ts-ignore 279 256 { ··· 292 269 queryKey: [ 293 270 { 294 271 infinite: true, 295 - params: { 296 - body: options.body ?? {}, 297 - headers: options.headers ?? {}, 298 - path: options.path ?? {}, 299 - query: options.query ?? {} 300 - }, 272 + params: createQueryKeyParams(options), 301 273 scope: 'callWithParameters' 302 274 } 303 275 ] ··· 324 296 }, 325 297 queryKey: [ 326 298 { 327 - params: { 328 - body: options.body ?? {}, 329 - headers: options.headers ?? {}, 330 - path: options.path ?? {}, 331 - query: options.query ?? {} 332 - }, 299 + params: createQueryKeyParams(options), 333 300 scope: 'callWithWeirdParameterNames' 334 301 } 335 302 ] ··· 356 323 }, 357 324 queryKey: [ 358 325 { 359 - params: { 360 - body: options.body ?? {}, 361 - headers: options.headers ?? {}, 362 - path: options.path ?? {}, 363 - query: options.query ?? {} 364 - }, 326 + params: createQueryKeyParams(options), 365 327 scope: 'getCallWithOptionalParam' 366 328 } 367 329 ] ··· 385 347 queryKey: [ 386 348 { 387 349 infinite: true, 388 - params: { 389 - body: options.body ?? {}, 390 - headers: options.headers ?? {}, 391 - path: options.path ?? {}, 392 - query: options.query ?? {} 393 - }, 350 + params: createQueryKeyParams(options), 394 351 scope: 'getCallWithOptionalParam' 395 352 } 396 353 ] ··· 407 364 }, 408 365 queryKey: [ 409 366 { 410 - params: { 411 - body: options.body ?? {}, 412 - headers: options.headers ?? {}, 413 - path: options.path ?? {}, 414 - query: options.query ?? {} 415 - }, 367 + params: createQueryKeyParams(options), 416 368 scope: 'postCallWithOptionalParam' 417 369 } 418 370 ] ··· 436 388 queryKey: [ 437 389 { 438 390 infinite: true, 439 - params: { 440 - body: options.body ?? {}, 441 - headers: options.headers ?? {}, 442 - path: options.path ?? {}, 443 - query: options.query ?? {} 444 - }, 391 + params: createQueryKeyParams(options), 445 392 scope: 'postCallWithOptionalParam' 446 393 } 447 394 ] ··· 468 415 }, 469 416 queryKey: [ 470 417 { 471 - params: { 472 - body: options?.body ?? {}, 473 - headers: options?.headers ?? {}, 474 - path: options?.path ?? {}, 475 - query: options?.query ?? {} 476 - }, 418 + params: createQueryKeyParams(options), 477 419 scope: 'postApiVbyApiVersionRequestBody' 478 420 } 479 421 ] ··· 500 442 }, 501 443 queryKey: [ 502 444 { 503 - params: { 504 - body: options?.body ?? {}, 505 - headers: options?.headers ?? {}, 506 - path: options?.path ?? {}, 507 - query: options?.query ?? {} 508 - }, 445 + params: createQueryKeyParams(options), 509 446 scope: 'postApiVbyApiVersionFormData' 510 447 } 511 448 ] ··· 532 469 }, 533 470 queryKey: [ 534 471 { 535 - params: { 536 - body: options?.body ?? {}, 537 - headers: options?.headers ?? {}, 538 - path: options?.path ?? {}, 539 - query: options?.query ?? {} 540 - }, 472 + params: createQueryKeyParams(options), 541 473 scope: 'callWithDefaultParameters' 542 474 } 543 475 ] ··· 554 486 }, 555 487 queryKey: [ 556 488 { 557 - params: { 558 - body: options?.body ?? {}, 559 - headers: options?.headers ?? {}, 560 - path: options?.path ?? {}, 561 - query: options?.query ?? {} 562 - }, 489 + params: createQueryKeyParams(options), 563 490 scope: 'callWithDefaultOptionalParameters' 564 491 } 565 492 ] ··· 596 523 }, 597 524 queryKey: [ 598 525 { 599 - params: { 600 - body: options?.body ?? {}, 601 - headers: options?.headers ?? {}, 602 - path: options?.path ?? {}, 603 - query: options?.query ?? {} 604 - }, 526 + params: createQueryKeyParams(options), 605 527 scope: 'duplicateName' 606 528 } 607 529 ] ··· 618 540 }, 619 541 queryKey: [ 620 542 { 621 - params: { 622 - body: options?.body ?? {}, 623 - headers: options?.headers ?? {}, 624 - path: options?.path ?? {}, 625 - query: options?.query ?? {} 626 - }, 543 + params: createQueryKeyParams(options), 627 544 scope: 'duplicateName1' 628 545 } 629 546 ] ··· 670 587 }, 671 588 queryKey: [ 672 589 { 673 - params: { 674 - body: options?.body ?? {}, 675 - headers: options?.headers ?? {}, 676 - path: options?.path ?? {}, 677 - query: options?.query ?? {} 678 - }, 590 + params: createQueryKeyParams(options), 679 591 scope: 'callWithNoContentResponse' 680 592 } 681 593 ] ··· 692 604 }, 693 605 queryKey: [ 694 606 { 695 - params: { 696 - body: options?.body ?? {}, 697 - headers: options?.headers ?? {}, 698 - path: options?.path ?? {}, 699 - query: options?.query ?? {} 700 - }, 607 + params: createQueryKeyParams(options), 701 608 scope: 'callWithResponseAndNoContentResponse' 702 609 } 703 610 ] ··· 714 621 }, 715 622 queryKey: [ 716 623 { 717 - params: { 718 - body: options?.body ?? {}, 719 - headers: options?.headers ?? {}, 720 - path: options?.path ?? {}, 721 - query: options?.query ?? {} 722 - }, 624 + params: createQueryKeyParams(options), 723 625 scope: 'dummyA' 724 626 } 725 627 ] ··· 736 638 }, 737 639 queryKey: [ 738 640 { 739 - params: { 740 - body: options?.body ?? {}, 741 - headers: options?.headers ?? {}, 742 - path: options?.path ?? {}, 743 - query: options?.query ?? {} 744 - }, 641 + params: createQueryKeyParams(options), 745 642 scope: 'dummyB' 746 643 } 747 644 ] ··· 758 655 }, 759 656 queryKey: [ 760 657 { 761 - params: { 762 - body: options?.body ?? {}, 763 - headers: options?.headers ?? {}, 764 - path: options?.path ?? {}, 765 - query: options?.query ?? {} 766 - }, 658 + params: createQueryKeyParams(options), 767 659 scope: 'callWithResponse' 768 660 } 769 661 ] ··· 780 672 }, 781 673 queryKey: [ 782 674 { 783 - params: { 784 - body: options?.body ?? {}, 785 - headers: options?.headers ?? {}, 786 - path: options?.path ?? {}, 787 - query: options?.query ?? {} 788 - }, 675 + params: createQueryKeyParams(options), 789 676 scope: 'callWithDuplicateResponses' 790 677 } 791 678 ] ··· 822 709 }, 823 710 queryKey: [ 824 711 { 825 - params: { 826 - body: options.body ?? {}, 827 - headers: options.headers ?? {}, 828 - path: options.path ?? {}, 829 - query: options.query ?? {} 830 - }, 712 + params: createQueryKeyParams(options), 831 713 scope: 'collectionFormat' 832 714 } 833 715 ] ··· 844 726 }, 845 727 queryKey: [ 846 728 { 847 - params: { 848 - body: options.body ?? {}, 849 - headers: options.headers ?? {}, 850 - path: options.path ?? {}, 851 - query: options.query ?? {} 852 - }, 729 + params: createQueryKeyParams(options), 853 730 scope: 'types' 854 731 } 855 732 ] ··· 866 743 }, 867 744 queryKey: [ 868 745 { 869 - params: { 870 - body: options.body ?? {}, 871 - headers: options.headers ?? {}, 872 - path: options.path ?? {}, 873 - query: options.query ?? {} 874 - }, 746 + params: createQueryKeyParams(options), 875 747 scope: 'uploadFile' 876 748 } 877 749 ] ··· 898 770 }, 899 771 queryKey: [ 900 772 { 901 - params: { 902 - body: options.body ?? {}, 903 - headers: options.headers ?? {}, 904 - path: options.path ?? {}, 905 - query: options.query ?? {} 906 - }, 773 + params: createQueryKeyParams(options), 907 774 scope: 'fileResponse' 908 775 } 909 776 ] ··· 920 787 }, 921 788 queryKey: [ 922 789 { 923 - params: { 924 - body: options.body ?? {}, 925 - headers: options.headers ?? {}, 926 - path: options.path ?? {}, 927 - query: options.query ?? {} 928 - }, 790 + params: createQueryKeyParams(options), 929 791 scope: 'complexTypes' 930 792 } 931 793 ] ··· 942 804 }, 943 805 queryKey: [ 944 806 { 945 - params: { 946 - body: options?.body ?? {}, 947 - headers: options?.headers ?? {}, 948 - path: options?.path ?? {}, 949 - query: options?.query ?? {} 950 - }, 807 + params: createQueryKeyParams(options), 951 808 scope: 'multipartRequest' 952 809 } 953 810 ] ··· 974 831 }, 975 832 queryKey: [ 976 833 { 977 - params: { 978 - body: options?.body ?? {}, 979 - headers: options?.headers ?? {}, 980 - path: options?.path ?? {}, 981 - query: options?.query ?? {} 982 - }, 834 + params: createQueryKeyParams(options), 983 835 scope: 'multipartResponse' 984 836 } 985 837 ] ··· 1006 858 }, 1007 859 queryKey: [ 1008 860 { 1009 - params: { 1010 - body: options?.body ?? {}, 1011 - headers: options?.headers ?? {}, 1012 - path: options?.path ?? {}, 1013 - query: options?.query ?? {} 1014 - }, 861 + params: createQueryKeyParams(options), 1015 862 scope: 'callWithResultFromHeader' 1016 863 } 1017 864 ] ··· 1038 885 }, 1039 886 queryKey: [ 1040 887 { 1041 - params: { 1042 - body: options.body ?? {}, 1043 - headers: options.headers ?? {}, 1044 - path: options.path ?? {}, 1045 - query: options.query ?? {} 1046 - }, 888 + params: createQueryKeyParams(options), 1047 889 scope: 'testErrorCode' 1048 890 } 1049 891 ] ··· 1070 912 }, 1071 913 queryKey: [ 1072 914 { 1073 - params: { 1074 - body: options.body ?? {}, 1075 - headers: options.headers ?? {}, 1076 - path: options.path ?? {}, 1077 - query: options.query ?? {} 1078 - }, 915 + params: createQueryKeyParams(options), 1079 916 scope: 'nonAsciiæøåÆøÅöôêÊ字符串' 1080 917 } 1081 918 ]
+31 -6
packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-axios-plugin-tanstack-react-query_transform/@tanstack/query.gen.ts.snap
··· 5 5 import { parentModelWithDates, modelWithDates, modelWithDatesArray, arrayOfDates, date, multipleResponses } from '../services.gen'; 6 6 import type { ParentModelWithDatesError, ParentModelWithDatesResponse, ModelWithDatesError, ModelWithDatesResponse, ModelWithDatesArrayError, ModelWithDatesArrayResponse, ArrayOfDatesError, ArrayOfDatesResponse, DateError, DateResponse, MultipleResponsesError, MultipleResponsesResponse } from '../types.gen'; 7 7 8 + type QueryKey = [ 9 + { 10 + infinite?: boolean; 11 + params: { 12 + body?: any; 13 + headers?: any; 14 + path?: any; 15 + query?: any; 16 + }; 17 + scope: string; 18 + } 19 + ]; 20 + 21 + const createQueryKeyParams = <T>(options?: Options<T>) => { 22 + const params: QueryKey[0]["params"] = {}; 23 + if (options?.body) { 24 + params.body = options.body; 25 + } 26 + if (options?.headers) { 27 + params.headers = options.headers; 28 + } 29 + if (options?.path) { 30 + params.path = options.path; 31 + } 32 + if (options?.query) { 33 + params.query = options.query; 34 + } 35 + return params; 36 + }; 37 + 8 38 export const parentModelWithDatesOptions = (options?: Options) => { return queryOptions({ 9 39 queryFn: async ({ queryKey }) => { 10 40 const { data } = await parentModelWithDates({ ··· 16 46 }, 17 47 queryKey: [ 18 48 { 19 - params: { 20 - body: options?.body ?? {}, 21 - headers: options?.headers ?? {}, 22 - path: options?.path ?? {}, 23 - query: options?.query ?? {} 24 - }, 49 + params: createQueryKeyParams(options), 25 50 scope: 'parentModelWithDates' 26 51 } 27 52 ]
+66 -229
packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-plugin-tanstack-react-query/@tanstack/query.gen.ts.snap
··· 5 5 import { export_, import_, apiVVersionOdataControllerCount, getCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, postCallWithoutParametersAndResponse, deleteCallWithoutParametersAndResponse, patchCallWithoutParametersAndResponse, deleteFoo, callWithDescriptions, deprecatedCall, callWithParameters, callWithWeirdParameterNames, getCallWithOptionalParam, postCallWithOptionalParam, postApiVbyApiVersionRequestBody, postApiVbyApiVersionFormData, callWithDefaultParameters, callWithDefaultOptionalParameters, callToTestOrderOfParams, duplicateName, duplicateName1, duplicateName2, duplicateName3, callWithNoContentResponse, callWithResponseAndNoContentResponse, dummyA, dummyB, callWithResponse, callWithDuplicateResponses, callWithResponses, collectionFormat, types, uploadFile, fileResponse, complexTypes, multipartRequest, multipartResponse, complexParams, callWithResultFromHeader, testErrorCode, nonAsciiæøåÆøÅöôêÊ字符串, putWithFormUrlEncoded } from '../services.gen'; 6 6 import type { ImportData, ImportError, ImportResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsError, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from '../types.gen'; 7 7 8 + type QueryKey = [ 9 + { 10 + infinite?: boolean; 11 + params: { 12 + body?: any; 13 + headers?: any; 14 + path?: any; 15 + query?: any; 16 + }; 17 + scope: string; 18 + } 19 + ]; 20 + 21 + const createQueryKeyParams = <T>(options?: Options<T>) => { 22 + const params: QueryKey[0]["params"] = {}; 23 + if (options?.body) { 24 + params.body = options.body; 25 + } 26 + if (options?.headers) { 27 + params.headers = options.headers; 28 + } 29 + if (options?.path) { 30 + params.path = options.path; 31 + } 32 + if (options?.query) { 33 + params.query = options.query; 34 + } 35 + return params; 36 + }; 37 + 8 38 export const exportOptions = (options?: Options) => { return queryOptions({ 9 39 queryFn: async ({ queryKey }) => { 10 40 const { data } = await export_({ ··· 16 46 }, 17 47 queryKey: [ 18 48 { 19 - params: { 20 - body: options?.body ?? {}, 21 - headers: options?.headers ?? {}, 22 - path: options?.path ?? {}, 23 - query: options?.query ?? {} 24 - }, 49 + params: createQueryKeyParams(options), 25 50 scope: 'export' 26 51 } 27 52 ] ··· 38 63 }, 39 64 queryKey: [ 40 65 { 41 - params: { 42 - body: options.body ?? {}, 43 - headers: options.headers ?? {}, 44 - path: options.path ?? {}, 45 - query: options.query ?? {} 46 - }, 66 + params: createQueryKeyParams(options), 47 67 scope: 'import' 48 68 } 49 69 ] ··· 70 90 }, 71 91 queryKey: [ 72 92 { 73 - params: { 74 - body: options?.body ?? {}, 75 - headers: options?.headers ?? {}, 76 - path: options?.path ?? {}, 77 - query: options?.query ?? {} 78 - }, 93 + params: createQueryKeyParams(options), 79 94 scope: 'apiVVersionOdataControllerCount' 80 95 } 81 96 ] ··· 92 107 }, 93 108 queryKey: [ 94 109 { 95 - params: { 96 - body: options?.body ?? {}, 97 - headers: options?.headers ?? {}, 98 - path: options?.path ?? {}, 99 - query: options?.query ?? {} 100 - }, 110 + params: createQueryKeyParams(options), 101 111 scope: 'getCallWithoutParametersAndResponse' 102 112 } 103 113 ] ··· 124 134 }, 125 135 queryKey: [ 126 136 { 127 - params: { 128 - body: options?.body ?? {}, 129 - headers: options?.headers ?? {}, 130 - path: options?.path ?? {}, 131 - query: options?.query ?? {} 132 - }, 137 + params: createQueryKeyParams(options), 133 138 scope: 'postCallWithoutParametersAndResponse' 134 139 } 135 140 ] ··· 186 191 }, 187 192 queryKey: [ 188 193 { 189 - params: { 190 - body: options?.body ?? {}, 191 - headers: options?.headers ?? {}, 192 - path: options?.path ?? {}, 193 - query: options?.query ?? {} 194 - }, 194 + params: createQueryKeyParams(options), 195 195 scope: 'callWithDescriptions' 196 196 } 197 197 ] ··· 218 218 }, 219 219 queryKey: [ 220 220 { 221 - params: { 222 - body: options.body ?? {}, 223 - headers: options.headers ?? {}, 224 - path: options.path ?? {}, 225 - query: options.query ?? {} 226 - }, 221 + params: createQueryKeyParams(options), 227 222 scope: 'deprecatedCall' 228 223 } 229 224 ] ··· 250 245 }, 251 246 queryKey: [ 252 247 { 253 - params: { 254 - body: options.body ?? {}, 255 - headers: options.headers ?? {}, 256 - path: options.path ?? {}, 257 - query: options.query ?? {} 258 - }, 248 + params: createQueryKeyParams(options), 259 249 scope: 'callWithParameters' 260 250 } 261 251 ] 262 252 }); }; 263 253 264 - type QueryKey = [ 265 - { 266 - infinite?: boolean; 267 - params: { 268 - body: any; 269 - headers: any; 270 - path: any; 271 - query: any; 272 - }; 273 - scope: string; 274 - } 275 - ]; 276 - 277 254 export const callWithParametersInfiniteOptions = (options: Options<CallWithParametersData>) => { return infiniteQueryOptions<void, DefaultError, InfiniteData<void>, QueryKey, unknown>( 278 255 // @ts-ignore 279 256 { ··· 292 269 queryKey: [ 293 270 { 294 271 infinite: true, 295 - params: { 296 - body: options.body ?? {}, 297 - headers: options.headers ?? {}, 298 - path: options.path ?? {}, 299 - query: options.query ?? {} 300 - }, 272 + params: createQueryKeyParams(options), 301 273 scope: 'callWithParameters' 302 274 } 303 275 ] ··· 324 296 }, 325 297 queryKey: [ 326 298 { 327 - params: { 328 - body: options.body ?? {}, 329 - headers: options.headers ?? {}, 330 - path: options.path ?? {}, 331 - query: options.query ?? {} 332 - }, 299 + params: createQueryKeyParams(options), 333 300 scope: 'callWithWeirdParameterNames' 334 301 } 335 302 ] ··· 356 323 }, 357 324 queryKey: [ 358 325 { 359 - params: { 360 - body: options.body ?? {}, 361 - headers: options.headers ?? {}, 362 - path: options.path ?? {}, 363 - query: options.query ?? {} 364 - }, 326 + params: createQueryKeyParams(options), 365 327 scope: 'getCallWithOptionalParam' 366 328 } 367 329 ] ··· 385 347 queryKey: [ 386 348 { 387 349 infinite: true, 388 - params: { 389 - body: options.body ?? {}, 390 - headers: options.headers ?? {}, 391 - path: options.path ?? {}, 392 - query: options.query ?? {} 393 - }, 350 + params: createQueryKeyParams(options), 394 351 scope: 'getCallWithOptionalParam' 395 352 } 396 353 ] ··· 407 364 }, 408 365 queryKey: [ 409 366 { 410 - params: { 411 - body: options.body ?? {}, 412 - headers: options.headers ?? {}, 413 - path: options.path ?? {}, 414 - query: options.query ?? {} 415 - }, 367 + params: createQueryKeyParams(options), 416 368 scope: 'postCallWithOptionalParam' 417 369 } 418 370 ] ··· 436 388 queryKey: [ 437 389 { 438 390 infinite: true, 439 - params: { 440 - body: options.body ?? {}, 441 - headers: options.headers ?? {}, 442 - path: options.path ?? {}, 443 - query: options.query ?? {} 444 - }, 391 + params: createQueryKeyParams(options), 445 392 scope: 'postCallWithOptionalParam' 446 393 } 447 394 ] ··· 468 415 }, 469 416 queryKey: [ 470 417 { 471 - params: { 472 - body: options?.body ?? {}, 473 - headers: options?.headers ?? {}, 474 - path: options?.path ?? {}, 475 - query: options?.query ?? {} 476 - }, 418 + params: createQueryKeyParams(options), 477 419 scope: 'postApiVbyApiVersionRequestBody' 478 420 } 479 421 ] ··· 500 442 }, 501 443 queryKey: [ 502 444 { 503 - params: { 504 - body: options?.body ?? {}, 505 - headers: options?.headers ?? {}, 506 - path: options?.path ?? {}, 507 - query: options?.query ?? {} 508 - }, 445 + params: createQueryKeyParams(options), 509 446 scope: 'postApiVbyApiVersionFormData' 510 447 } 511 448 ] ··· 532 469 }, 533 470 queryKey: [ 534 471 { 535 - params: { 536 - body: options?.body ?? {}, 537 - headers: options?.headers ?? {}, 538 - path: options?.path ?? {}, 539 - query: options?.query ?? {} 540 - }, 472 + params: createQueryKeyParams(options), 541 473 scope: 'callWithDefaultParameters' 542 474 } 543 475 ] ··· 554 486 }, 555 487 queryKey: [ 556 488 { 557 - params: { 558 - body: options?.body ?? {}, 559 - headers: options?.headers ?? {}, 560 - path: options?.path ?? {}, 561 - query: options?.query ?? {} 562 - }, 489 + params: createQueryKeyParams(options), 563 490 scope: 'callWithDefaultOptionalParameters' 564 491 } 565 492 ] ··· 596 523 }, 597 524 queryKey: [ 598 525 { 599 - params: { 600 - body: options?.body ?? {}, 601 - headers: options?.headers ?? {}, 602 - path: options?.path ?? {}, 603 - query: options?.query ?? {} 604 - }, 526 + params: createQueryKeyParams(options), 605 527 scope: 'duplicateName' 606 528 } 607 529 ] ··· 618 540 }, 619 541 queryKey: [ 620 542 { 621 - params: { 622 - body: options?.body ?? {}, 623 - headers: options?.headers ?? {}, 624 - path: options?.path ?? {}, 625 - query: options?.query ?? {} 626 - }, 543 + params: createQueryKeyParams(options), 627 544 scope: 'duplicateName1' 628 545 } 629 546 ] ··· 670 587 }, 671 588 queryKey: [ 672 589 { 673 - params: { 674 - body: options?.body ?? {}, 675 - headers: options?.headers ?? {}, 676 - path: options?.path ?? {}, 677 - query: options?.query ?? {} 678 - }, 590 + params: createQueryKeyParams(options), 679 591 scope: 'callWithNoContentResponse' 680 592 } 681 593 ] ··· 692 604 }, 693 605 queryKey: [ 694 606 { 695 - params: { 696 - body: options?.body ?? {}, 697 - headers: options?.headers ?? {}, 698 - path: options?.path ?? {}, 699 - query: options?.query ?? {} 700 - }, 607 + params: createQueryKeyParams(options), 701 608 scope: 'callWithResponseAndNoContentResponse' 702 609 } 703 610 ] ··· 714 621 }, 715 622 queryKey: [ 716 623 { 717 - params: { 718 - body: options?.body ?? {}, 719 - headers: options?.headers ?? {}, 720 - path: options?.path ?? {}, 721 - query: options?.query ?? {} 722 - }, 624 + params: createQueryKeyParams(options), 723 625 scope: 'dummyA' 724 626 } 725 627 ] ··· 736 638 }, 737 639 queryKey: [ 738 640 { 739 - params: { 740 - body: options?.body ?? {}, 741 - headers: options?.headers ?? {}, 742 - path: options?.path ?? {}, 743 - query: options?.query ?? {} 744 - }, 641 + params: createQueryKeyParams(options), 745 642 scope: 'dummyB' 746 643 } 747 644 ] ··· 758 655 }, 759 656 queryKey: [ 760 657 { 761 - params: { 762 - body: options?.body ?? {}, 763 - headers: options?.headers ?? {}, 764 - path: options?.path ?? {}, 765 - query: options?.query ?? {} 766 - }, 658 + params: createQueryKeyParams(options), 767 659 scope: 'callWithResponse' 768 660 } 769 661 ] ··· 780 672 }, 781 673 queryKey: [ 782 674 { 783 - params: { 784 - body: options?.body ?? {}, 785 - headers: options?.headers ?? {}, 786 - path: options?.path ?? {}, 787 - query: options?.query ?? {} 788 - }, 675 + params: createQueryKeyParams(options), 789 676 scope: 'callWithDuplicateResponses' 790 677 } 791 678 ] ··· 822 709 }, 823 710 queryKey: [ 824 711 { 825 - params: { 826 - body: options.body ?? {}, 827 - headers: options.headers ?? {}, 828 - path: options.path ?? {}, 829 - query: options.query ?? {} 830 - }, 712 + params: createQueryKeyParams(options), 831 713 scope: 'collectionFormat' 832 714 } 833 715 ] ··· 844 726 }, 845 727 queryKey: [ 846 728 { 847 - params: { 848 - body: options.body ?? {}, 849 - headers: options.headers ?? {}, 850 - path: options.path ?? {}, 851 - query: options.query ?? {} 852 - }, 729 + params: createQueryKeyParams(options), 853 730 scope: 'types' 854 731 } 855 732 ] ··· 866 743 }, 867 744 queryKey: [ 868 745 { 869 - params: { 870 - body: options.body ?? {}, 871 - headers: options.headers ?? {}, 872 - path: options.path ?? {}, 873 - query: options.query ?? {} 874 - }, 746 + params: createQueryKeyParams(options), 875 747 scope: 'uploadFile' 876 748 } 877 749 ] ··· 898 770 }, 899 771 queryKey: [ 900 772 { 901 - params: { 902 - body: options.body ?? {}, 903 - headers: options.headers ?? {}, 904 - path: options.path ?? {}, 905 - query: options.query ?? {} 906 - }, 773 + params: createQueryKeyParams(options), 907 774 scope: 'fileResponse' 908 775 } 909 776 ] ··· 920 787 }, 921 788 queryKey: [ 922 789 { 923 - params: { 924 - body: options.body ?? {}, 925 - headers: options.headers ?? {}, 926 - path: options.path ?? {}, 927 - query: options.query ?? {} 928 - }, 790 + params: createQueryKeyParams(options), 929 791 scope: 'complexTypes' 930 792 } 931 793 ] ··· 942 804 }, 943 805 queryKey: [ 944 806 { 945 - params: { 946 - body: options?.body ?? {}, 947 - headers: options?.headers ?? {}, 948 - path: options?.path ?? {}, 949 - query: options?.query ?? {} 950 - }, 807 + params: createQueryKeyParams(options), 951 808 scope: 'multipartRequest' 952 809 } 953 810 ] ··· 974 831 }, 975 832 queryKey: [ 976 833 { 977 - params: { 978 - body: options?.body ?? {}, 979 - headers: options?.headers ?? {}, 980 - path: options?.path ?? {}, 981 - query: options?.query ?? {} 982 - }, 834 + params: createQueryKeyParams(options), 983 835 scope: 'multipartResponse' 984 836 } 985 837 ] ··· 1006 858 }, 1007 859 queryKey: [ 1008 860 { 1009 - params: { 1010 - body: options?.body ?? {}, 1011 - headers: options?.headers ?? {}, 1012 - path: options?.path ?? {}, 1013 - query: options?.query ?? {} 1014 - }, 861 + params: createQueryKeyParams(options), 1015 862 scope: 'callWithResultFromHeader' 1016 863 } 1017 864 ] ··· 1038 885 }, 1039 886 queryKey: [ 1040 887 { 1041 - params: { 1042 - body: options.body ?? {}, 1043 - headers: options.headers ?? {}, 1044 - path: options.path ?? {}, 1045 - query: options.query ?? {} 1046 - }, 888 + params: createQueryKeyParams(options), 1047 889 scope: 'testErrorCode' 1048 890 } 1049 891 ] ··· 1070 912 }, 1071 913 queryKey: [ 1072 914 { 1073 - params: { 1074 - body: options.body ?? {}, 1075 - headers: options.headers ?? {}, 1076 - path: options.path ?? {}, 1077 - query: options.query ?? {} 1078 - }, 915 + params: createQueryKeyParams(options), 1079 916 scope: 'nonAsciiæøåÆøÅöôêÊ字符串' 1080 917 } 1081 918 ]
+31 -6
packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-plugin-tanstack-react-query_transform/@tanstack/query.gen.ts.snap
··· 5 5 import { parentModelWithDates, modelWithDates, modelWithDatesArray, arrayOfDates, date, multipleResponses } from '../services.gen'; 6 6 import type { ParentModelWithDatesError, ParentModelWithDatesResponse, ModelWithDatesError, ModelWithDatesResponse, ModelWithDatesArrayError, ModelWithDatesArrayResponse, ArrayOfDatesError, ArrayOfDatesResponse, DateError, DateResponse, MultipleResponsesError, MultipleResponsesResponse } from '../types.gen'; 7 7 8 + type QueryKey = [ 9 + { 10 + infinite?: boolean; 11 + params: { 12 + body?: any; 13 + headers?: any; 14 + path?: any; 15 + query?: any; 16 + }; 17 + scope: string; 18 + } 19 + ]; 20 + 21 + const createQueryKeyParams = <T>(options?: Options<T>) => { 22 + const params: QueryKey[0]["params"] = {}; 23 + if (options?.body) { 24 + params.body = options.body; 25 + } 26 + if (options?.headers) { 27 + params.headers = options.headers; 28 + } 29 + if (options?.path) { 30 + params.path = options.path; 31 + } 32 + if (options?.query) { 33 + params.query = options.query; 34 + } 35 + return params; 36 + }; 37 + 8 38 export const parentModelWithDatesOptions = (options?: Options) => { return queryOptions({ 9 39 queryFn: async ({ queryKey }) => { 10 40 const { data } = await parentModelWithDates({ ··· 16 46 }, 17 47 queryKey: [ 18 48 { 19 - params: { 20 - body: options?.body ?? {}, 21 - headers: options?.headers ?? {}, 22 - path: options?.path ?? {}, 23 - query: options?.query ?? {} 24 - }, 49 + params: createQueryKeyParams(options), 25 50 scope: 'parentModelWithDates' 26 51 } 27 52 ]