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

Configure Feed

Select the types of activity you want to include in your feed.

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

chore: progress on TanStack Query plugin

authored by

Lubos and committed by
GitHub
37a991a9 450d7852

+1575 -305
+8 -6
packages/openapi-ts/src/compiler/index.ts
··· 126 126 } 127 127 } 128 128 129 + // TODO: flatten keys, it is hard to quickly find the desired method 129 130 export const compiler = { 131 + arrayLiteralExpression: types.createArrayLiteralExpression, 132 + awaitExpression: types.createAwaitExpression, 133 + callExpression: module.createCallExpression, 130 134 class: { 131 135 constructor: classes.createConstructorDeclaration, 132 136 create: classes.createClassDeclaration, 133 137 method: classes.createMethodDeclaration, 134 138 }, 139 + constVariable: module.createConstVariable, 135 140 convert: { 136 141 expressionToStatement: convert.convertExpressionToStatement, 137 142 }, ··· 147 152 if: transform.createIfStatement, 148 153 safeAccess: transform.createSafeAccessExpression, 149 154 }, 155 + objectExpression: types.createObjectType, 150 156 return: { 151 157 functionCall: _return.createReturnFunctionCall, 152 - statement: _return.createReturnStatement, 153 158 }, 159 + returnVariable: _return.createReturnVariable, 154 160 transform: { 155 161 alias: transform.createAlias, 156 162 arrayTransformMutation: transform.createArrayTransformMutation, ··· 171 177 union: typedef.createTypeUnionNode, 172 178 }, 173 179 types: { 174 - array: types.createArrayType, 175 - call: module.createCallExpression, 176 - const: module.createConstVariable, 180 + arrowFunction: types.createArrowFunction, 177 181 enum: types.createEnumDeclaration, 178 - function: types.createFunction, 179 182 namespace: types.createNamespaceDeclaration, 180 - object: types.createObjectType, 181 183 }, 182 184 utils: { 183 185 isTsNode: utils.isTsNode,
+15 -3
packages/openapi-ts/src/compiler/module.ts
··· 29 29 type ImportExportItem = ImportExportItemObject | string; 30 30 31 31 export const createCallExpression = ({ 32 - parameters, 32 + parameters = [], 33 33 functionName, 34 34 types, 35 35 }: { 36 36 functionName: string | ts.PropertyAccessExpression; 37 - parameters: Array<string | ts.Expression>; 37 + parameters?: Array<string | ts.Expression>; 38 38 types?: ReadonlyArray<ts.TypeNode>; 39 39 }) => { 40 40 const expression = ··· 102 102 export const createConstVariable = ({ 103 103 comment, 104 104 constAssertion, 105 + destructure, 105 106 expression, 106 107 exportConst, 107 108 name, ··· 109 110 }: { 110 111 comment?: Comments; 111 112 constAssertion?: boolean; 113 + destructure?: boolean; 112 114 exportConst?: boolean; 113 115 expression: ts.Expression; 114 116 name: string; ··· 120 122 ts.factory.createTypeReferenceNode('const'), 121 123 ) 122 124 : expression; 125 + const nameIdentifier = ts.factory.createIdentifier(name); 123 126 const declaration = ts.factory.createVariableDeclaration( 124 - ts.factory.createIdentifier(name), 127 + destructure 128 + ? ts.factory.createObjectBindingPattern([ 129 + ts.factory.createBindingElement( 130 + undefined, 131 + undefined, 132 + nameIdentifier, 133 + undefined, 134 + ), 135 + ]) 136 + : nameIdentifier, 125 137 undefined, 126 138 typeName ? ts.factory.createTypeReferenceNode(typeName) : undefined, 127 139 initializer,
+10 -5
packages/openapi-ts/src/compiler/return.ts
··· 3 3 import { createCallExpression } from './module'; 4 4 import { isType } from './utils'; 5 5 6 + const createReturnStatement = ({ 7 + expression, 8 + }: { 9 + expression?: ts.Expression; 10 + }) => ts.factory.createReturnStatement(expression); 11 + 6 12 /** 7 13 * Create a return function call statement. 8 14 * Example `return fn<string>(params)`. ··· 37 43 return statement; 38 44 }; 39 45 40 - export const createReturnStatement = ({ 41 - expression, 42 - }: { 43 - expression?: ts.Expression; 44 - }) => ts.factory.createReturnStatement(expression); 46 + export const createReturnVariable = ({ name }: { name: string }) => 47 + createReturnStatement({ 48 + expression: ts.factory.createIdentifier(name), 49 + });
+43 -61
packages/openapi-ts/src/compiler/transform.ts
··· 2 2 3 3 import { convertExpressionToStatement } from './convert'; 4 4 import { createCallExpression } from './module'; 5 - import { createReturnStatement } from './return'; 5 + import { createReturnVariable } from './return'; 6 + import { createArrowFunction } from './types'; 6 7 7 8 export const createSafeAccessExpression = (path: string[]) => 8 9 path ··· 183 184 undefined, 184 185 undefined, 185 186 [ 186 - ts.factory.createArrowFunction( 187 - undefined, 188 - undefined, 189 - [ 190 - ts.factory.createParameterDeclaration( 191 - undefined, 192 - undefined, 193 - ts.factory.createIdentifier('item'), 194 - undefined, 195 - undefined, 196 - undefined, 197 - ), 187 + createArrowFunction({ 188 + parameters: [ 189 + { 190 + name: 'item', 191 + }, 198 192 ], 199 - undefined, 200 - ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), 201 - transformExpression, 202 - ), 193 + statements: transformExpression, 194 + }), 203 195 ], 204 196 ), 205 197 ), ··· 241 233 name: string; 242 234 transform: string; 243 235 }) => { 244 - const transformFunction = ts.factory.createArrowFunction( 245 - undefined, 246 - undefined, 247 - [ 248 - ts.factory.createParameterDeclaration( 249 - undefined, 250 - undefined, 251 - ts.factory.createIdentifier('data'), 252 - undefined, 253 - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), 254 - undefined, 255 - ), 236 + const transformFunction = createArrowFunction({ 237 + multiLine: true, 238 + parameters: [ 239 + { 240 + name: 'data', 241 + type: ts.SyntaxKind.AnyKeyword, 242 + }, 256 243 ], 257 - undefined, 258 - ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), 259 - ts.factory.createBlock( 260 - [ 261 - createIfStatement({ 262 - expression: createCallExpression({ 263 - functionName: ts.factory.createPropertyAccessExpression( 264 - ts.factory.createIdentifier('Array'), 265 - ts.factory.createIdentifier('isArray'), 266 - ), 267 - parameters: ['data'], 268 - }), 269 - thenStatement: ts.factory.createBlock( 270 - [ 271 - convertExpressionToStatement({ 272 - expression: createCallExpression({ 273 - functionName: ts.factory.createPropertyAccessExpression( 274 - ts.factory.createIdentifier('data'), 275 - ts.factory.createIdentifier('forEach'), 276 - ), 277 - parameters: [transform], 278 - }), 279 - }), 280 - ], 281 - true, 244 + statements: [ 245 + createIfStatement({ 246 + expression: createCallExpression({ 247 + functionName: ts.factory.createPropertyAccessExpression( 248 + ts.factory.createIdentifier('Array'), 249 + ts.factory.createIdentifier('isArray'), 282 250 ), 283 - }), 284 - createReturnStatement({ 285 - expression: ts.factory.createIdentifier('data'), 251 + parameters: ['data'], 286 252 }), 287 - ], 288 - true, 289 - ), 290 - ); 253 + thenStatement: ts.factory.createBlock( 254 + [ 255 + convertExpressionToStatement({ 256 + expression: createCallExpression({ 257 + functionName: ts.factory.createPropertyAccessExpression( 258 + ts.factory.createIdentifier('data'), 259 + ts.factory.createIdentifier('forEach'), 260 + ), 261 + parameters: [transform], 262 + }), 263 + }), 264 + ], 265 + true, 266 + ), 267 + }), 268 + createReturnVariable({ 269 + name: 'data', 270 + }), 271 + ], 272 + }); 291 273 292 274 const declaration = ts.factory.createVariableStatement( 293 275 [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
+67 -23
packages/openapi-ts/src/compiler/types.ts
··· 14 14 export type FunctionParameter = { 15 15 accessLevel?: AccessLevel; 16 16 default?: any; 17 + destructure?: boolean; 17 18 isReadOnly?: boolean; 18 19 isRequired?: boolean; 19 20 name: string; ··· 30 31 */ 31 32 export const toExpression = <T = unknown>({ 32 33 identifiers = [], 33 - shorthand = false, 34 - unescape = false, 34 + isValueAccess, 35 + shorthand, 36 + unescape, 35 37 value, 36 38 }: { 37 39 identifiers?: string[]; 40 + isValueAccess?: boolean; 38 41 shorthand?: boolean; 39 42 unescape?: boolean; 40 43 value: T; ··· 44 47 } 45 48 46 49 if (Array.isArray(value)) { 47 - return createArrayType({ arr: value }); 50 + return createArrayLiteralExpression({ elements: value }); 48 51 } 49 52 50 53 if (typeof value === 'object') { ··· 60 63 } 61 64 62 65 if (typeof value === 'string') { 66 + if (isValueAccess) { 67 + // TODO; handle more than single nested level, i.e. foo.bar.baz 68 + const parts = value.split('.'); 69 + return ts.factory.createPropertyAccessExpression( 70 + ts.factory.createIdentifier(parts[0]), 71 + ts.factory.createIdentifier(parts[1]), 72 + ); 73 + } 63 74 return ots.string(value, unescape); 64 75 } 65 76 }; ··· 93 104 * @returns ts.ParameterDeclaration[] 94 105 */ 95 106 export const toParameterDeclarations = (parameters: FunctionParameter[]) => 96 - parameters.map((p) => { 97 - const modifiers = toAccessLevelModifiers(p.accessLevel); 98 - if (p.isReadOnly) { 99 - modifiers.push(ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)); 107 + parameters.map((parameter) => { 108 + let modifiers = toAccessLevelModifiers(parameter.accessLevel); 109 + 110 + if (parameter.isReadOnly) { 111 + modifiers = [ 112 + ...modifiers, 113 + ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword), 114 + ]; 100 115 } 116 + 117 + const nameIdentifier = ts.factory.createIdentifier(parameter.name); 118 + 101 119 return ts.factory.createParameterDeclaration( 102 120 modifiers, 103 121 undefined, 104 - ts.factory.createIdentifier(p.name), 105 - p.isRequired !== undefined && !p.isRequired 122 + parameter.destructure 123 + ? ts.factory.createObjectBindingPattern([ 124 + ts.factory.createBindingElement( 125 + undefined, 126 + undefined, 127 + nameIdentifier, 128 + undefined, 129 + ), 130 + ]) 131 + : nameIdentifier, 132 + parameter.isRequired !== undefined && !parameter.isRequired 106 133 ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) 107 134 : undefined, 108 - p.type !== undefined ? createTypeNode(p.type) : undefined, 109 - p.default !== undefined ? toExpression({ value: p.default }) : undefined, 135 + parameter.type !== undefined ? createTypeNode(parameter.type) : undefined, 136 + parameter.default !== undefined 137 + ? toExpression({ value: parameter.default }) 138 + : undefined, 110 139 ); 111 140 }); 112 141 113 142 /** 114 - * Create Function type expression. 143 + * Create arrow function type expression. 115 144 */ 116 - export const createFunction = ({ 145 + export const createArrowFunction = ({ 117 146 async, 118 147 comment, 119 148 multiLine, ··· 126 155 multiLine?: boolean; 127 156 parameters?: FunctionParameter[]; 128 157 returnType?: string | ts.TypeNode; 129 - statements?: ts.Statement[]; 158 + statements?: ts.Statement[] | ts.Expression; 130 159 }) => { 131 160 const expression = ts.factory.createArrowFunction( 132 161 async ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)] : undefined, ··· 134 163 toParameterDeclarations(parameters), 135 164 returnType ? createTypeNode(returnType) : undefined, 136 165 undefined, 137 - ts.factory.createBlock(statements, multiLine), 166 + Array.isArray(statements) 167 + ? ts.factory.createBlock(statements, multiLine) 168 + : statements, 138 169 ); 139 170 if (comment) { 140 171 addLeadingJSDocComment(expression, comment); ··· 148 179 * @param multiLine - if the array should be multiline. 149 180 * @returns ts.ArrayLiteralExpression 150 181 */ 151 - export const createArrayType = <T>({ 152 - arr, 182 + export const createArrayLiteralExpression = <T>({ 183 + elements, 153 184 multiLine = false, 154 185 }: { 155 - arr: T[]; 186 + elements: T[]; 156 187 multiLine?: boolean; 157 - }): ts.ArrayLiteralExpression => 158 - ts.factory.createArrayLiteralExpression( 159 - arr.map((value) => toExpression({ value })).filter(isType<ts.Expression>), 160 - // Multiline if the array contains objects, or if specified by the user. 161 - (!Array.isArray(arr[0]) && typeof arr[0] === 'object') || multiLine, 188 + }): ts.ArrayLiteralExpression => { 189 + const expression = ts.factory.createArrayLiteralExpression( 190 + elements 191 + .map((value) => (isTsNode(value) ? value : toExpression({ value }))) 192 + .filter(isType<ts.Expression>), 193 + // multiline if array contains objects 194 + multiLine || 195 + (!Array.isArray(elements[0]) && typeof elements[0] === 'object'), 162 196 ); 197 + return expression; 198 + }; 199 + 200 + export const createAwaitExpression = ({ 201 + expression, 202 + }: { 203 + expression: ts.Expression; 204 + }) => ts.factory.createAwaitExpression(expression); 163 205 164 206 export type ObjectValue = 165 207 | { spread: string } 166 208 | { 209 + isValueAccess?: boolean; 167 210 key: string; 168 211 value: any; 169 212 }; ··· 242 285 identifiers: identifiers.includes(value.key) 243 286 ? Object.keys(value.value) 244 287 : [], 288 + isValueAccess: value.isValueAccess, 245 289 shorthand, 246 290 unescape, 247 291 value: value.value,
+7
packages/openapi-ts/src/generate/client.ts
··· 7 7 8 8 const require = createRequire(import.meta.url); 9 9 10 + export const clientModulePath = () => { 11 + const config = getConfig(); 12 + return config.client.bundle ? './client' : config.client.name; 13 + }; 14 + 15 + export const clientOptionsTypeName = () => 'Options'; 16 + 10 17 /** 11 18 * (optional) Creates a `client.ts` file containing the same exports as a 12 19 * standalone client package. Creates a `core` directory containing the modules
+182 -14
packages/openapi-ts/src/generate/plugins.ts
··· 1 1 import { compiler, TypeScriptFile } from '../compiler'; 2 2 import type { Operation } from '../openApi'; 3 + import { isOperationParameterRequired } from '../openApi/common/parser/operation'; 3 4 import type { Client } from '../types/client'; 4 5 import type { Files } from '../types/utils'; 5 - import { getConfig } from '../utils/config'; 6 - import { toOperationName } from './services'; 6 + import { getConfig, isStandaloneClient } from '../utils/config'; 7 + import { setUniqueTypeName } from '../utils/type'; 8 + import { unique } from '../utils/unique'; 9 + import { clientModulePath, clientOptionsTypeName } from './client'; 10 + import { 11 + generateImport, 12 + operationDataTypeName, 13 + operationOptionsType, 14 + toOperationName, 15 + } from './services'; 7 16 8 17 const toQueryOptionsName = (operation: Operation) => 9 18 `${toOperationName(operation, false)}Options`; ··· 17 26 }) => { 18 27 const config = getConfig(); 19 28 29 + const isStandalone = isStandaloneClient(config); 30 + 31 + if (!isStandalone) { 32 + // plugins work only with standalone clients 33 + return; 34 + } 35 + 20 36 for (const plugin of config.plugins) { 21 37 files[plugin.name] = new TypeScriptFile({ 22 38 dir: config.output.path, ··· 24 40 }); 25 41 26 42 if (plugin.name === '@tanstack/react-query') { 43 + files[plugin.name].addImport({ 44 + imports: [ 45 + { 46 + asType: true, 47 + name: clientOptionsTypeName(), 48 + }, 49 + ], 50 + module: clientModulePath(), 51 + }); 52 + 53 + let imports: string[] = []; 54 + 27 55 const queryOptionsId = 'queryOptions'; 28 56 29 57 let importsServices: Parameters< ··· 35 63 36 64 for (const service of client.services) { 37 65 for (const operation of service.operations) { 66 + if (operation.parameters.length) { 67 + generateImport({ 68 + client, 69 + meta: { 70 + // TODO: this should be exact ref to operation for consistency, 71 + // but name should work too as operation ID is unique 72 + $ref: operation.name, 73 + name: operation.name, 74 + }, 75 + nameTransformer: operationDataTypeName, 76 + onImport: (imported) => { 77 + imports = [...imports, imported]; 78 + }, 79 + }); 80 + } 81 + 38 82 const queryFn = toOperationName(operation, true); 39 83 40 - const expression = compiler.types.function({ 41 - // TODO: parameters. Probably want to copy options from service call, 42 - // then inside the queryOptions function split them into request parameters 43 - // and client options. Request parameters will go into query key, the rest will 44 - // go only to the query function. We also need to ensure the service method 45 - // returns only data and throws on error 46 - parameters: [], 84 + const awaitServiceExpression = compiler.awaitExpression({ 85 + expression: compiler.callExpression({ 86 + functionName: queryFn, 87 + parameters: [ 88 + compiler.objectExpression({ 89 + multiLine: true, 90 + obj: [ 91 + { 92 + spread: 'queryKey[0].params', 93 + }, 94 + { 95 + key: 'throwOnError', 96 + value: true, 97 + }, 98 + ], 99 + }), 100 + ], 101 + }), 102 + }); 103 + 104 + const { name: importedType } = setUniqueTypeName({ 105 + client, 106 + meta: { 107 + // TODO: this should be exact ref to operation for consistency, 108 + // but name should work too as operation ID is unique 109 + $ref: operation.name, 110 + name: operation.name, 111 + }, 112 + nameTransformer: operationDataTypeName, 113 + }); 114 + 115 + const queryFnArrowFunction = compiler.types.arrowFunction({ 116 + async: true, 117 + multiLine: true, 118 + parameters: [ 119 + { 120 + destructure: true, 121 + name: 'queryKey', 122 + }, 123 + ], 124 + statements: [ 125 + compiler.constVariable({ 126 + destructure: true, 127 + expression: awaitServiceExpression, 128 + name: 'data', 129 + }), 130 + compiler.returnVariable({ 131 + name: 'data', 132 + }), 133 + ], 134 + }); 135 + 136 + const isRequired = isOperationParameterRequired(operation.parameters); 137 + 138 + const expression = compiler.types.arrowFunction({ 139 + parameters: [ 140 + { 141 + isRequired, 142 + name: 'options', 143 + type: operationOptionsType(importedType), 144 + }, 145 + { 146 + isRequired: false, 147 + name: 'queryOpts', 148 + type: 'object', 149 + }, 150 + ], 47 151 statements: [ 48 152 compiler.return.functionCall({ 49 153 args: [ 50 - compiler.types.object({ 51 - identifiers: ['queryFn'], 154 + compiler.objectExpression({ 52 155 obj: [ 53 156 { 157 + spread: 'queryOpts', 158 + }, 159 + { 54 160 key: 'queryFn', 55 - value: queryFn, 161 + value: queryFnArrowFunction, 56 162 }, 57 163 { 58 164 key: 'queryKey', 59 165 // TODO: queryKey strategy 60 - value: ['foo'], 166 + value: compiler.arrayLiteralExpression({ 167 + elements: [ 168 + compiler.objectExpression({ 169 + obj: [ 170 + { 171 + key: 'scope', 172 + value: operation.name, 173 + }, 174 + { 175 + key: 'params', 176 + value: compiler.objectExpression({ 177 + obj: [ 178 + { 179 + isValueAccess: true, 180 + key: 'body', 181 + value: isRequired 182 + ? 'options.body' 183 + : 'options?.body', 184 + }, 185 + { 186 + isValueAccess: true, 187 + key: 'headers', 188 + value: isRequired 189 + ? 'options.headers' 190 + : 'options?.headers', 191 + }, 192 + { 193 + isValueAccess: true, 194 + key: 'path', 195 + value: isRequired 196 + ? 'options.path' 197 + : 'options?.path', 198 + }, 199 + { 200 + isValueAccess: true, 201 + key: 'query', 202 + value: isRequired 203 + ? 'options.query' 204 + : 'options?.query', 205 + }, 206 + ], 207 + }), 208 + }, 209 + ], 210 + }), 211 + ], 212 + }), 61 213 }, 62 214 ], 63 215 }), ··· 66 218 }), 67 219 ], 68 220 }); 69 - const statement = compiler.types.const({ 221 + const statement = compiler.constVariable({ 222 + comment: [ 223 + 'TODO: describe arguments, options is Hey API, queryOpts is TanStack Query', 224 + ], 70 225 exportConst: true, 71 226 expression, 72 227 name: toQueryOptionsName(operation), ··· 95 250 imports: importsServices, 96 251 module: `./${files.services.getName(false)}`, 97 252 }); 253 + } 254 + 255 + if (files.types && !files.types.isEmpty()) { 256 + const importedTypes = imports.filter(unique).map((name) => ({ 257 + asType: true, 258 + name, 259 + })); 260 + if (importedTypes.length) { 261 + files[plugin.name].addImport({ 262 + imports: importedTypes, 263 + module: `./${files.types.getName(false)}`, 264 + }); 265 + } 98 266 } 99 267 } 100 268 }
+2 -2
packages/openapi-ts/src/generate/schemas.ts
··· 69 69 const addSchema = (name: string, schema: object) => { 70 70 const validName = `$${ensureValidTypeScriptJavaScriptIdentifier(name)}`; 71 71 const obj = ensureValidSchemaOutput(schema); 72 - const expression = compiler.types.object({ obj }); 73 - const statement = compiler.types.const({ 72 + const expression = compiler.objectExpression({ obj }); 73 + const statement = compiler.constVariable({ 74 74 constAssertion: true, 75 75 exportConst: true, 76 76 expression,
+29 -21
packages/openapi-ts/src/generate/services.ts
··· 10 10 } from '../compiler'; 11 11 import type { ObjectValue } from '../compiler/types'; 12 12 import type { Model, Operation, OperationParameter, Service } from '../openApi'; 13 + import { isOperationParameterRequired } from '../openApi/common/parser/operation'; 13 14 import type { Client } from '../types/client'; 14 15 import type { Files } from '../types/utils'; 15 16 import { getConfig, isStandaloneClient } from '../utils/config'; ··· 18 19 import { transformServiceName } from '../utils/transform'; 19 20 import { setUniqueTypeName } from '../utils/type'; 20 21 import { unique } from '../utils/unique'; 22 + import { clientModulePath, clientOptionsTypeName } from './client'; 21 23 22 24 type OnNode = (node: Node) => void; 23 25 type OnImport = (name: string) => void; 24 26 25 - const generateImport = ({ 27 + export const generateImport = ({ 26 28 meta, 27 29 onImport, 28 30 ...setUniqueTypeNameArgs ··· 56 58 57 59 export const operationResponseTypeName = (name: string) => 58 60 `${camelcase(name, { pascalCase: true })}Response`; 61 + 62 + /** 63 + * @param importedType unique type name returned from `setUniqueTypeName()` 64 + * @returns options type 65 + */ 66 + export const operationOptionsType = (importedType?: string) => { 67 + const optionsName = clientOptionsTypeName(); 68 + return importedType ? `${optionsName}<${importedType}>` : optionsName; 69 + }; 59 70 60 71 const toOperationParamType = ( 61 72 client: Client, ··· 74 85 nameTransformer: operationDataTypeName, 75 86 }); 76 87 77 - const isRequired = operation.parameters.some( 78 - (parameter) => parameter.isRequired, 79 - ); 88 + const isRequired = isOperationParameterRequired(operation.parameters); 80 89 81 90 if (isStandaloneClient(config)) { 82 91 return [ 83 92 { 84 93 isRequired, 85 94 name: 'options', 86 - type: importedType ? `Options<${importedType}>` : 'Options', 95 + type: operationOptionsType(importedType), 87 96 }, 88 97 ]; 89 98 } ··· 305 314 ]; 306 315 } 307 316 308 - return compiler.types.object({ 317 + return compiler.objectExpression({ 309 318 identifiers: ['responseTransformer'], 310 319 obj, 311 320 }); ··· 393 402 obj.errors = errors; 394 403 } 395 404 396 - return compiler.types.object({ 405 + return compiler.objectExpression({ 397 406 identifiers: [ 398 407 'body', 399 408 'cookies', ··· 569 578 570 579 if (!config.services.asClass && !config.name) { 571 580 for (const operation of service.operations) { 572 - const expression = compiler.types.function({ 581 + const expression = compiler.types.arrowFunction({ 573 582 parameters: toOperationParamType(client, operation), 574 583 returnType: isStandalone 575 584 ? undefined ··· 581 590 onClientImport, 582 591 ), 583 592 }); 584 - const statement = compiler.types.const({ 593 + const statement = compiler.constVariable({ 585 594 comment: toOperationComment(operation), 586 595 exportConst: true, 587 596 expression, ··· 682 691 683 692 // define client first 684 693 if (isStandalone) { 685 - const innerFunction = compiler.types.call({ 686 - functionName: 'createConfig', 687 - parameters: [], 688 - }); 689 - const outerFunction = compiler.types.call({ 690 - functionName: 'createClient', 691 - parameters: [innerFunction], 692 - }); 693 - const statement = compiler.types.const({ 694 + const statement = compiler.constVariable({ 694 695 exportConst: true, 695 - expression: outerFunction, 696 + expression: compiler.callExpression({ 697 + functionName: 'createClient', 698 + parameters: [ 699 + compiler.callExpression({ 700 + functionName: 'createConfig', 701 + }), 702 + ], 703 + }), 696 704 name: 'client', 697 705 }); 698 706 files.services.add(statement); ··· 725 733 'createConfig', 726 734 { 727 735 asType: true, 728 - name: 'Options', 736 + name: clientOptionsTypeName(), 729 737 }, 730 738 ...clientImports.filter(unique), 731 739 ], 732 - module: config.client.bundle ? './client' : config.client.name, 740 + module: clientModulePath(), 733 741 }); 734 742 } else { 735 743 if (config.client.name === 'angular') {
+5 -5
packages/openapi-ts/src/generate/transformers.ts
··· 161 161 return model.in === 'response' 162 162 ? [ 163 163 compiler.convert.expressionToStatement({ 164 - expression: compiler.types.call({ 164 + expression: compiler.callExpression({ 165 165 functionName: nameModelResponseTransformer, 166 166 parameters: [dataVariableName], 167 167 }), ··· 206 206 return result; 207 207 } 208 208 209 - const expression = compiler.types.function({ 209 + const expression = compiler.types.arrowFunction({ 210 210 async, 211 211 multiLine: true, 212 212 parameters: [ ··· 216 216 ], 217 217 statements: [ 218 218 ...statements, 219 - compiler.return.statement({ 220 - expression: ts.factory.createIdentifier(dataVariableName), 219 + compiler.returnVariable({ 220 + name: dataVariableName, 221 221 }), 222 222 ], 223 223 }); 224 - const statement = compiler.types.const({ 224 + const statement = compiler.constVariable({ 225 225 exportConst: true, 226 226 expression, 227 227 name,
+16 -11
packages/openapi-ts/src/generate/types.ts
··· 8 8 } from '../compiler'; 9 9 import type { Model, OperationParameter } from '../openApi'; 10 10 import type { Method } from '../openApi/common/interfaces/client'; 11 + import { isOperationParameterRequired } from '../openApi/common/parser/operation'; 11 12 import type { Client } from '../types/client'; 12 13 import type { Files } from '../types/utils'; 13 14 import { getConfig, isStandaloneClient } from '../utils/config'; ··· 194 195 onCreated: (name) => { 195 196 // create a separate JavaScript object export 196 197 if (config.types.enums === 'javascript') { 197 - const expression = compiler.types.object({ 198 + const expression = compiler.objectExpression({ 198 199 comments, 199 200 multiLine: true, 200 201 obj: properties, 201 202 unescape: true, 202 203 }); 203 - const node = compiler.types.const({ 204 + const node = compiler.constVariable({ 204 205 comment, 205 206 constAssertion: true, 206 207 exportConst: true, ··· 340 341 const headerParameters: OperationParameter = { 341 342 ...emptyModel, 342 343 in: 'header', 343 - isRequired: operation.parameters 344 - .filter((parameter) => parameter.in === 'header') 345 - .some((parameter) => parameter.isRequired), 344 + isRequired: isOperationParameterRequired( 345 + operation.parameters.filter( 346 + (parameter) => parameter.in === 'header', 347 + ), 348 + ), 346 349 mediaType: null, 347 350 name: isStandalone ? 'headers' : 'header', 348 351 prop: isStandalone ? 'headers' : 'header', ··· 353 356 const pathParameters: OperationParameter = { 354 357 ...emptyModel, 355 358 in: 'path', 356 - isRequired: operation.parameters 357 - .filter((parameter) => parameter.in === 'path') 358 - .some((parameter) => parameter.isRequired), 359 + isRequired: isOperationParameterRequired( 360 + operation.parameters.filter((parameter) => parameter.in === 'path'), 361 + ), 359 362 mediaType: null, 360 363 name: 'path', 361 364 prop: 'path', ··· 366 369 const queryParameters: OperationParameter = { 367 370 ...emptyModel, 368 371 in: 'query', 369 - isRequired: operation.parameters 370 - .filter((parameter) => parameter.in === 'query') 371 - .some((parameter) => parameter.isRequired), 372 + isRequired: isOperationParameterRequired( 373 + operation.parameters.filter( 374 + (parameter) => parameter.in === 'query', 375 + ), 376 + ), 372 377 mediaType: null, 373 378 name: 'query', 374 379 prop: 'query',
+15 -1
packages/openapi-ts/src/openApi/common/parser/operation.ts
··· 1 1 import camelCase from 'camelcase'; 2 2 3 3 import { getConfig, isStandaloneClient } from '../../../utils/config'; 4 - import type { OperationResponse } from '../interfaces/client'; 4 + import type { 5 + OperationParameter, 6 + OperationResponse, 7 + } from '../interfaces/client'; 5 8 import { sanitizeNamespaceIdentifier } from './sanitize'; 6 9 7 10 /** ··· 49 52 return header.name; 50 53 } 51 54 return null; 55 + }; 56 + 57 + /** 58 + * Does this operation have at least one required parameter? 59 + * @returns boolean 60 + */ 61 + export const isOperationParameterRequired = ( 62 + parameters: OperationParameter[], 63 + ) => { 64 + const isRequired = parameters.some((parameter) => parameter.isRequired); 65 + return isRequired; 52 66 }; 53 67 54 68 /**
+1037 -135
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch_plugin_tanstack-react-query/tanstack-query.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { Options } from '@hey-api/client-fetch'; 3 4 import { queryOptions } from '@tanstack/react-query'; 4 5 import { export_, import_, apiVVersionOdataControllerCount, getCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, postCallWithoutParametersAndResponse, deleteCallWithoutParametersAndResponse, optionsCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, 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 + import type { ImportData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CollectionFormatData, TypesData, UploadFileData, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; 5 7 6 - export const exportOptions = () => { return queryOptions({ 7 - queryFn: export_, 8 - queryKey: ['foo'] 8 + /** 9 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 10 + */ 11 + export const exportOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 12 + ...queryOpts, 13 + queryFn: async ({ queryKey }) => { 14 + const { data } = await export_({ 15 + ...queryKey[0].params, 16 + throwOnError: true 17 + }); 18 + return data; 19 + }, 20 + queryKey: [ 21 + { 22 + scope: 'export', 23 + params: { 24 + body: options?.body, 25 + headers: options?.headers, 26 + path: options?.path, 27 + query: options?.query 28 + } 29 + } 30 + ] 9 31 }); }; 10 32 11 - export const importOptions = () => { return queryOptions({ 12 - queryFn: import_, 13 - queryKey: ['foo'] 33 + /** 34 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 35 + */ 36 + export const importOptions = (options: Options<ImportData>, queryOpts?: object) => { return queryOptions({ 37 + ...queryOpts, 38 + queryFn: async ({ queryKey }) => { 39 + const { data } = await import_({ 40 + ...queryKey[0].params, 41 + throwOnError: true 42 + }); 43 + return data; 44 + }, 45 + queryKey: [ 46 + { 47 + scope: 'import', 48 + params: { 49 + body: options.body, 50 + headers: options.headers, 51 + path: options.path, 52 + query: options.query 53 + } 54 + } 55 + ] 14 56 }); }; 15 57 16 - export const apiVVersionOdataControllerCountOptions = () => { return queryOptions({ 17 - queryFn: apiVVersionOdataControllerCount, 18 - queryKey: ['foo'] 58 + /** 59 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 60 + */ 61 + export const apiVVersionOdataControllerCountOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 62 + ...queryOpts, 63 + queryFn: async ({ queryKey }) => { 64 + const { data } = await apiVVersionOdataControllerCount({ 65 + ...queryKey[0].params, 66 + throwOnError: true 67 + }); 68 + return data; 69 + }, 70 + queryKey: [ 71 + { 72 + scope: 'apiVVersionOdataControllerCount', 73 + params: { 74 + body: options?.body, 75 + headers: options?.headers, 76 + path: options?.path, 77 + query: options?.query 78 + } 79 + } 80 + ] 19 81 }); }; 20 82 21 - export const getCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 22 - queryFn: getCallWithoutParametersAndResponse, 23 - queryKey: ['foo'] 83 + /** 84 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 85 + */ 86 + export const getCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 87 + ...queryOpts, 88 + queryFn: async ({ queryKey }) => { 89 + const { data } = await getCallWithoutParametersAndResponse({ 90 + ...queryKey[0].params, 91 + throwOnError: true 92 + }); 93 + return data; 94 + }, 95 + queryKey: [ 96 + { 97 + scope: 'getCallWithoutParametersAndResponse', 98 + params: { 99 + body: options?.body, 100 + headers: options?.headers, 101 + path: options?.path, 102 + query: options?.query 103 + } 104 + } 105 + ] 24 106 }); }; 25 107 26 - export const putCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 27 - queryFn: putCallWithoutParametersAndResponse, 28 - queryKey: ['foo'] 108 + /** 109 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 110 + */ 111 + export const putCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 112 + ...queryOpts, 113 + queryFn: async ({ queryKey }) => { 114 + const { data } = await putCallWithoutParametersAndResponse({ 115 + ...queryKey[0].params, 116 + throwOnError: true 117 + }); 118 + return data; 119 + }, 120 + queryKey: [ 121 + { 122 + scope: 'putCallWithoutParametersAndResponse', 123 + params: { 124 + body: options?.body, 125 + headers: options?.headers, 126 + path: options?.path, 127 + query: options?.query 128 + } 129 + } 130 + ] 29 131 }); }; 30 132 31 - export const postCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 32 - queryFn: postCallWithoutParametersAndResponse, 33 - queryKey: ['foo'] 133 + /** 134 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 135 + */ 136 + export const postCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 137 + ...queryOpts, 138 + queryFn: async ({ queryKey }) => { 139 + const { data } = await postCallWithoutParametersAndResponse({ 140 + ...queryKey[0].params, 141 + throwOnError: true 142 + }); 143 + return data; 144 + }, 145 + queryKey: [ 146 + { 147 + scope: 'postCallWithoutParametersAndResponse', 148 + params: { 149 + body: options?.body, 150 + headers: options?.headers, 151 + path: options?.path, 152 + query: options?.query 153 + } 154 + } 155 + ] 34 156 }); }; 35 157 36 - export const deleteCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 37 - queryFn: deleteCallWithoutParametersAndResponse, 38 - queryKey: ['foo'] 158 + /** 159 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 160 + */ 161 + export const deleteCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 162 + ...queryOpts, 163 + queryFn: async ({ queryKey }) => { 164 + const { data } = await deleteCallWithoutParametersAndResponse({ 165 + ...queryKey[0].params, 166 + throwOnError: true 167 + }); 168 + return data; 169 + }, 170 + queryKey: [ 171 + { 172 + scope: 'deleteCallWithoutParametersAndResponse', 173 + params: { 174 + body: options?.body, 175 + headers: options?.headers, 176 + path: options?.path, 177 + query: options?.query 178 + } 179 + } 180 + ] 39 181 }); }; 40 182 41 - export const optionsCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 42 - queryFn: optionsCallWithoutParametersAndResponse, 43 - queryKey: ['foo'] 183 + /** 184 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 185 + */ 186 + export const optionsCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 187 + ...queryOpts, 188 + queryFn: async ({ queryKey }) => { 189 + const { data } = await optionsCallWithoutParametersAndResponse({ 190 + ...queryKey[0].params, 191 + throwOnError: true 192 + }); 193 + return data; 194 + }, 195 + queryKey: [ 196 + { 197 + scope: 'optionsCallWithoutParametersAndResponse', 198 + params: { 199 + body: options?.body, 200 + headers: options?.headers, 201 + path: options?.path, 202 + query: options?.query 203 + } 204 + } 205 + ] 44 206 }); }; 45 207 46 - export const headCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 47 - queryFn: headCallWithoutParametersAndResponse, 48 - queryKey: ['foo'] 208 + /** 209 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 210 + */ 211 + export const headCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 212 + ...queryOpts, 213 + queryFn: async ({ queryKey }) => { 214 + const { data } = await headCallWithoutParametersAndResponse({ 215 + ...queryKey[0].params, 216 + throwOnError: true 217 + }); 218 + return data; 219 + }, 220 + queryKey: [ 221 + { 222 + scope: 'headCallWithoutParametersAndResponse', 223 + params: { 224 + body: options?.body, 225 + headers: options?.headers, 226 + path: options?.path, 227 + query: options?.query 228 + } 229 + } 230 + ] 49 231 }); }; 50 232 51 - export const patchCallWithoutParametersAndResponseOptions = () => { return queryOptions({ 52 - queryFn: patchCallWithoutParametersAndResponse, 53 - queryKey: ['foo'] 233 + /** 234 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 235 + */ 236 + export const patchCallWithoutParametersAndResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 237 + ...queryOpts, 238 + queryFn: async ({ queryKey }) => { 239 + const { data } = await patchCallWithoutParametersAndResponse({ 240 + ...queryKey[0].params, 241 + throwOnError: true 242 + }); 243 + return data; 244 + }, 245 + queryKey: [ 246 + { 247 + scope: 'patchCallWithoutParametersAndResponse', 248 + params: { 249 + body: options?.body, 250 + headers: options?.headers, 251 + path: options?.path, 252 + query: options?.query 253 + } 254 + } 255 + ] 54 256 }); }; 55 257 56 - export const deleteFooOptions = () => { return queryOptions({ 57 - queryFn: deleteFoo, 58 - queryKey: ['foo'] 258 + /** 259 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 260 + */ 261 + export const deleteFooOptions = (options: Options<DeleteFooData3>, queryOpts?: object) => { return queryOptions({ 262 + ...queryOpts, 263 + queryFn: async ({ queryKey }) => { 264 + const { data } = await deleteFoo({ 265 + ...queryKey[0].params, 266 + throwOnError: true 267 + }); 268 + return data; 269 + }, 270 + queryKey: [ 271 + { 272 + scope: 'deleteFoo', 273 + params: { 274 + body: options.body, 275 + headers: options.headers, 276 + path: options.path, 277 + query: options.query 278 + } 279 + } 280 + ] 59 281 }); }; 60 282 61 - export const callWithDescriptionsOptions = () => { return queryOptions({ 62 - queryFn: callWithDescriptions, 63 - queryKey: ['foo'] 283 + /** 284 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 285 + */ 286 + export const callWithDescriptionsOptions = (options?: Options<CallWithDescriptionsData>, queryOpts?: object) => { return queryOptions({ 287 + ...queryOpts, 288 + queryFn: async ({ queryKey }) => { 289 + const { data } = await callWithDescriptions({ 290 + ...queryKey[0].params, 291 + throwOnError: true 292 + }); 293 + return data; 294 + }, 295 + queryKey: [ 296 + { 297 + scope: 'callWithDescriptions', 298 + params: { 299 + body: options?.body, 300 + headers: options?.headers, 301 + path: options?.path, 302 + query: options?.query 303 + } 304 + } 305 + ] 64 306 }); }; 65 307 66 - export const deprecatedCallOptions = () => { return queryOptions({ 67 - queryFn: deprecatedCall, 68 - queryKey: ['foo'] 308 + /** 309 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 310 + */ 311 + export const deprecatedCallOptions = (options: Options<DeprecatedCallData>, queryOpts?: object) => { return queryOptions({ 312 + ...queryOpts, 313 + queryFn: async ({ queryKey }) => { 314 + const { data } = await deprecatedCall({ 315 + ...queryKey[0].params, 316 + throwOnError: true 317 + }); 318 + return data; 319 + }, 320 + queryKey: [ 321 + { 322 + scope: 'deprecatedCall', 323 + params: { 324 + body: options.body, 325 + headers: options.headers, 326 + path: options.path, 327 + query: options.query 328 + } 329 + } 330 + ] 69 331 }); }; 70 332 71 - export const callWithParametersOptions = () => { return queryOptions({ 72 - queryFn: callWithParameters, 73 - queryKey: ['foo'] 333 + /** 334 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 335 + */ 336 + export const callWithParametersOptions = (options: Options<CallWithParametersData>, queryOpts?: object) => { return queryOptions({ 337 + ...queryOpts, 338 + queryFn: async ({ queryKey }) => { 339 + const { data } = await callWithParameters({ 340 + ...queryKey[0].params, 341 + throwOnError: true 342 + }); 343 + return data; 344 + }, 345 + queryKey: [ 346 + { 347 + scope: 'callWithParameters', 348 + params: { 349 + body: options.body, 350 + headers: options.headers, 351 + path: options.path, 352 + query: options.query 353 + } 354 + } 355 + ] 74 356 }); }; 75 357 76 - export const callWithWeirdParameterNamesOptions = () => { return queryOptions({ 77 - queryFn: callWithWeirdParameterNames, 78 - queryKey: ['foo'] 358 + /** 359 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 360 + */ 361 + export const callWithWeirdParameterNamesOptions = (options: Options<CallWithWeirdParameterNamesData>, queryOpts?: object) => { return queryOptions({ 362 + ...queryOpts, 363 + queryFn: async ({ queryKey }) => { 364 + const { data } = await callWithWeirdParameterNames({ 365 + ...queryKey[0].params, 366 + throwOnError: true 367 + }); 368 + return data; 369 + }, 370 + queryKey: [ 371 + { 372 + scope: 'callWithWeirdParameterNames', 373 + params: { 374 + body: options.body, 375 + headers: options.headers, 376 + path: options.path, 377 + query: options.query 378 + } 379 + } 380 + ] 79 381 }); }; 80 382 81 - export const getCallWithOptionalParamOptions = () => { return queryOptions({ 82 - queryFn: getCallWithOptionalParam, 83 - queryKey: ['foo'] 383 + /** 384 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 385 + */ 386 + export const getCallWithOptionalParamOptions = (options: Options<GetCallWithOptionalParamData>, queryOpts?: object) => { return queryOptions({ 387 + ...queryOpts, 388 + queryFn: async ({ queryKey }) => { 389 + const { data } = await getCallWithOptionalParam({ 390 + ...queryKey[0].params, 391 + throwOnError: true 392 + }); 393 + return data; 394 + }, 395 + queryKey: [ 396 + { 397 + scope: 'getCallWithOptionalParam', 398 + params: { 399 + body: options.body, 400 + headers: options.headers, 401 + path: options.path, 402 + query: options.query 403 + } 404 + } 405 + ] 84 406 }); }; 85 407 86 - export const postCallWithOptionalParamOptions = () => { return queryOptions({ 87 - queryFn: postCallWithOptionalParam, 88 - queryKey: ['foo'] 408 + /** 409 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 410 + */ 411 + export const postCallWithOptionalParamOptions = (options: Options<PostCallWithOptionalParamData>, queryOpts?: object) => { return queryOptions({ 412 + ...queryOpts, 413 + queryFn: async ({ queryKey }) => { 414 + const { data } = await postCallWithOptionalParam({ 415 + ...queryKey[0].params, 416 + throwOnError: true 417 + }); 418 + return data; 419 + }, 420 + queryKey: [ 421 + { 422 + scope: 'postCallWithOptionalParam', 423 + params: { 424 + body: options.body, 425 + headers: options.headers, 426 + path: options.path, 427 + query: options.query 428 + } 429 + } 430 + ] 89 431 }); }; 90 432 91 - export const postApiVbyApiVersionRequestBodyOptions = () => { return queryOptions({ 92 - queryFn: postApiVbyApiVersionRequestBody, 93 - queryKey: ['foo'] 433 + /** 434 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 435 + */ 436 + export const postApiVbyApiVersionRequestBodyOptions = (options?: Options<PostApiVbyApiVersionRequestBodyData>, queryOpts?: object) => { return queryOptions({ 437 + ...queryOpts, 438 + queryFn: async ({ queryKey }) => { 439 + const { data } = await postApiVbyApiVersionRequestBody({ 440 + ...queryKey[0].params, 441 + throwOnError: true 442 + }); 443 + return data; 444 + }, 445 + queryKey: [ 446 + { 447 + scope: 'postApiVbyApiVersionRequestBody', 448 + params: { 449 + body: options?.body, 450 + headers: options?.headers, 451 + path: options?.path, 452 + query: options?.query 453 + } 454 + } 455 + ] 94 456 }); }; 95 457 96 - export const postApiVbyApiVersionFormDataOptions = () => { return queryOptions({ 97 - queryFn: postApiVbyApiVersionFormData, 98 - queryKey: ['foo'] 458 + /** 459 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 460 + */ 461 + export const postApiVbyApiVersionFormDataOptions = (options?: Options<PostApiVbyApiVersionFormDataData>, queryOpts?: object) => { return queryOptions({ 462 + ...queryOpts, 463 + queryFn: async ({ queryKey }) => { 464 + const { data } = await postApiVbyApiVersionFormData({ 465 + ...queryKey[0].params, 466 + throwOnError: true 467 + }); 468 + return data; 469 + }, 470 + queryKey: [ 471 + { 472 + scope: 'postApiVbyApiVersionFormData', 473 + params: { 474 + body: options?.body, 475 + headers: options?.headers, 476 + path: options?.path, 477 + query: options?.query 478 + } 479 + } 480 + ] 99 481 }); }; 100 482 101 - export const callWithDefaultParametersOptions = () => { return queryOptions({ 102 - queryFn: callWithDefaultParameters, 103 - queryKey: ['foo'] 483 + /** 484 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 485 + */ 486 + export const callWithDefaultParametersOptions = (options?: Options<CallWithDefaultParametersData>, queryOpts?: object) => { return queryOptions({ 487 + ...queryOpts, 488 + queryFn: async ({ queryKey }) => { 489 + const { data } = await callWithDefaultParameters({ 490 + ...queryKey[0].params, 491 + throwOnError: true 492 + }); 493 + return data; 494 + }, 495 + queryKey: [ 496 + { 497 + scope: 'callWithDefaultParameters', 498 + params: { 499 + body: options?.body, 500 + headers: options?.headers, 501 + path: options?.path, 502 + query: options?.query 503 + } 504 + } 505 + ] 104 506 }); }; 105 507 106 - export const callWithDefaultOptionalParametersOptions = () => { return queryOptions({ 107 - queryFn: callWithDefaultOptionalParameters, 108 - queryKey: ['foo'] 508 + /** 509 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 510 + */ 511 + export const callWithDefaultOptionalParametersOptions = (options?: Options<CallWithDefaultOptionalParametersData>, queryOpts?: object) => { return queryOptions({ 512 + ...queryOpts, 513 + queryFn: async ({ queryKey }) => { 514 + const { data } = await callWithDefaultOptionalParameters({ 515 + ...queryKey[0].params, 516 + throwOnError: true 517 + }); 518 + return data; 519 + }, 520 + queryKey: [ 521 + { 522 + scope: 'callWithDefaultOptionalParameters', 523 + params: { 524 + body: options?.body, 525 + headers: options?.headers, 526 + path: options?.path, 527 + query: options?.query 528 + } 529 + } 530 + ] 109 531 }); }; 110 532 111 - export const callToTestOrderOfParamsOptions = () => { return queryOptions({ 112 - queryFn: callToTestOrderOfParams, 113 - queryKey: ['foo'] 533 + /** 534 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 535 + */ 536 + export const callToTestOrderOfParamsOptions = (options: Options<CallToTestOrderOfParamsData>, queryOpts?: object) => { return queryOptions({ 537 + ...queryOpts, 538 + queryFn: async ({ queryKey }) => { 539 + const { data } = await callToTestOrderOfParams({ 540 + ...queryKey[0].params, 541 + throwOnError: true 542 + }); 543 + return data; 544 + }, 545 + queryKey: [ 546 + { 547 + scope: 'callToTestOrderOfParams', 548 + params: { 549 + body: options.body, 550 + headers: options.headers, 551 + path: options.path, 552 + query: options.query 553 + } 554 + } 555 + ] 114 556 }); }; 115 557 116 - export const duplicateNameOptions = () => { return queryOptions({ 117 - queryFn: duplicateName, 118 - queryKey: ['foo'] 558 + /** 559 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 560 + */ 561 + export const duplicateNameOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 562 + ...queryOpts, 563 + queryFn: async ({ queryKey }) => { 564 + const { data } = await duplicateName({ 565 + ...queryKey[0].params, 566 + throwOnError: true 567 + }); 568 + return data; 569 + }, 570 + queryKey: [ 571 + { 572 + scope: 'duplicateName', 573 + params: { 574 + body: options?.body, 575 + headers: options?.headers, 576 + path: options?.path, 577 + query: options?.query 578 + } 579 + } 580 + ] 119 581 }); }; 120 582 121 - export const duplicateName1Options = () => { return queryOptions({ 122 - queryFn: duplicateName1, 123 - queryKey: ['foo'] 583 + /** 584 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 585 + */ 586 + export const duplicateName1Options = (options?: Options, queryOpts?: object) => { return queryOptions({ 587 + ...queryOpts, 588 + queryFn: async ({ queryKey }) => { 589 + const { data } = await duplicateName1({ 590 + ...queryKey[0].params, 591 + throwOnError: true 592 + }); 593 + return data; 594 + }, 595 + queryKey: [ 596 + { 597 + scope: 'duplicateName1', 598 + params: { 599 + body: options?.body, 600 + headers: options?.headers, 601 + path: options?.path, 602 + query: options?.query 603 + } 604 + } 605 + ] 124 606 }); }; 125 607 126 - export const duplicateName2Options = () => { return queryOptions({ 127 - queryFn: duplicateName2, 128 - queryKey: ['foo'] 608 + /** 609 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 610 + */ 611 + export const duplicateName2Options = (options?: Options, queryOpts?: object) => { return queryOptions({ 612 + ...queryOpts, 613 + queryFn: async ({ queryKey }) => { 614 + const { data } = await duplicateName2({ 615 + ...queryKey[0].params, 616 + throwOnError: true 617 + }); 618 + return data; 619 + }, 620 + queryKey: [ 621 + { 622 + scope: 'duplicateName2', 623 + params: { 624 + body: options?.body, 625 + headers: options?.headers, 626 + path: options?.path, 627 + query: options?.query 628 + } 629 + } 630 + ] 129 631 }); }; 130 632 131 - export const duplicateName3Options = () => { return queryOptions({ 132 - queryFn: duplicateName3, 133 - queryKey: ['foo'] 633 + /** 634 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 635 + */ 636 + export const duplicateName3Options = (options?: Options, queryOpts?: object) => { return queryOptions({ 637 + ...queryOpts, 638 + queryFn: async ({ queryKey }) => { 639 + const { data } = await duplicateName3({ 640 + ...queryKey[0].params, 641 + throwOnError: true 642 + }); 643 + return data; 644 + }, 645 + queryKey: [ 646 + { 647 + scope: 'duplicateName3', 648 + params: { 649 + body: options?.body, 650 + headers: options?.headers, 651 + path: options?.path, 652 + query: options?.query 653 + } 654 + } 655 + ] 134 656 }); }; 135 657 136 - export const callWithNoContentResponseOptions = () => { return queryOptions({ 137 - queryFn: callWithNoContentResponse, 138 - queryKey: ['foo'] 658 + /** 659 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 660 + */ 661 + export const callWithNoContentResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 662 + ...queryOpts, 663 + queryFn: async ({ queryKey }) => { 664 + const { data } = await callWithNoContentResponse({ 665 + ...queryKey[0].params, 666 + throwOnError: true 667 + }); 668 + return data; 669 + }, 670 + queryKey: [ 671 + { 672 + scope: 'callWithNoContentResponse', 673 + params: { 674 + body: options?.body, 675 + headers: options?.headers, 676 + path: options?.path, 677 + query: options?.query 678 + } 679 + } 680 + ] 139 681 }); }; 140 682 141 - export const callWithResponseAndNoContentResponseOptions = () => { return queryOptions({ 142 - queryFn: callWithResponseAndNoContentResponse, 143 - queryKey: ['foo'] 683 + /** 684 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 685 + */ 686 + export const callWithResponseAndNoContentResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 687 + ...queryOpts, 688 + queryFn: async ({ queryKey }) => { 689 + const { data } = await callWithResponseAndNoContentResponse({ 690 + ...queryKey[0].params, 691 + throwOnError: true 692 + }); 693 + return data; 694 + }, 695 + queryKey: [ 696 + { 697 + scope: 'callWithResponseAndNoContentResponse', 698 + params: { 699 + body: options?.body, 700 + headers: options?.headers, 701 + path: options?.path, 702 + query: options?.query 703 + } 704 + } 705 + ] 144 706 }); }; 145 707 146 - export const dummyAOptions = () => { return queryOptions({ 147 - queryFn: dummyA, 148 - queryKey: ['foo'] 708 + /** 709 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 710 + */ 711 + export const dummyAOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 712 + ...queryOpts, 713 + queryFn: async ({ queryKey }) => { 714 + const { data } = await dummyA({ 715 + ...queryKey[0].params, 716 + throwOnError: true 717 + }); 718 + return data; 719 + }, 720 + queryKey: [ 721 + { 722 + scope: 'dummyA', 723 + params: { 724 + body: options?.body, 725 + headers: options?.headers, 726 + path: options?.path, 727 + query: options?.query 728 + } 729 + } 730 + ] 149 731 }); }; 150 732 151 - export const dummyBOptions = () => { return queryOptions({ 152 - queryFn: dummyB, 153 - queryKey: ['foo'] 733 + /** 734 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 735 + */ 736 + export const dummyBOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 737 + ...queryOpts, 738 + queryFn: async ({ queryKey }) => { 739 + const { data } = await dummyB({ 740 + ...queryKey[0].params, 741 + throwOnError: true 742 + }); 743 + return data; 744 + }, 745 + queryKey: [ 746 + { 747 + scope: 'dummyB', 748 + params: { 749 + body: options?.body, 750 + headers: options?.headers, 751 + path: options?.path, 752 + query: options?.query 753 + } 754 + } 755 + ] 154 756 }); }; 155 757 156 - export const callWithResponseOptions = () => { return queryOptions({ 157 - queryFn: callWithResponse, 158 - queryKey: ['foo'] 758 + /** 759 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 760 + */ 761 + export const callWithResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 762 + ...queryOpts, 763 + queryFn: async ({ queryKey }) => { 764 + const { data } = await callWithResponse({ 765 + ...queryKey[0].params, 766 + throwOnError: true 767 + }); 768 + return data; 769 + }, 770 + queryKey: [ 771 + { 772 + scope: 'callWithResponse', 773 + params: { 774 + body: options?.body, 775 + headers: options?.headers, 776 + path: options?.path, 777 + query: options?.query 778 + } 779 + } 780 + ] 159 781 }); }; 160 782 161 - export const callWithDuplicateResponsesOptions = () => { return queryOptions({ 162 - queryFn: callWithDuplicateResponses, 163 - queryKey: ['foo'] 783 + /** 784 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 785 + */ 786 + export const callWithDuplicateResponsesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 787 + ...queryOpts, 788 + queryFn: async ({ queryKey }) => { 789 + const { data } = await callWithDuplicateResponses({ 790 + ...queryKey[0].params, 791 + throwOnError: true 792 + }); 793 + return data; 794 + }, 795 + queryKey: [ 796 + { 797 + scope: 'callWithDuplicateResponses', 798 + params: { 799 + body: options?.body, 800 + headers: options?.headers, 801 + path: options?.path, 802 + query: options?.query 803 + } 804 + } 805 + ] 164 806 }); }; 165 807 166 - export const callWithResponsesOptions = () => { return queryOptions({ 167 - queryFn: callWithResponses, 168 - queryKey: ['foo'] 808 + /** 809 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 810 + */ 811 + export const callWithResponsesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 812 + ...queryOpts, 813 + queryFn: async ({ queryKey }) => { 814 + const { data } = await callWithResponses({ 815 + ...queryKey[0].params, 816 + throwOnError: true 817 + }); 818 + return data; 819 + }, 820 + queryKey: [ 821 + { 822 + scope: 'callWithResponses', 823 + params: { 824 + body: options?.body, 825 + headers: options?.headers, 826 + path: options?.path, 827 + query: options?.query 828 + } 829 + } 830 + ] 169 831 }); }; 170 832 171 - export const collectionFormatOptions = () => { return queryOptions({ 172 - queryFn: collectionFormat, 173 - queryKey: ['foo'] 833 + /** 834 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 835 + */ 836 + export const collectionFormatOptions = (options: Options<CollectionFormatData>, queryOpts?: object) => { return queryOptions({ 837 + ...queryOpts, 838 + queryFn: async ({ queryKey }) => { 839 + const { data } = await collectionFormat({ 840 + ...queryKey[0].params, 841 + throwOnError: true 842 + }); 843 + return data; 844 + }, 845 + queryKey: [ 846 + { 847 + scope: 'collectionFormat', 848 + params: { 849 + body: options.body, 850 + headers: options.headers, 851 + path: options.path, 852 + query: options.query 853 + } 854 + } 855 + ] 174 856 }); }; 175 857 176 - export const typesOptions = () => { return queryOptions({ 177 - queryFn: types, 178 - queryKey: ['foo'] 858 + /** 859 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 860 + */ 861 + export const typesOptions = (options: Options<TypesData>, queryOpts?: object) => { return queryOptions({ 862 + ...queryOpts, 863 + queryFn: async ({ queryKey }) => { 864 + const { data } = await types({ 865 + ...queryKey[0].params, 866 + throwOnError: true 867 + }); 868 + return data; 869 + }, 870 + queryKey: [ 871 + { 872 + scope: 'types', 873 + params: { 874 + body: options.body, 875 + headers: options.headers, 876 + path: options.path, 877 + query: options.query 878 + } 879 + } 880 + ] 179 881 }); }; 180 882 181 - export const uploadFileOptions = () => { return queryOptions({ 182 - queryFn: uploadFile, 183 - queryKey: ['foo'] 883 + /** 884 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 885 + */ 886 + export const uploadFileOptions = (options: Options<UploadFileData>, queryOpts?: object) => { return queryOptions({ 887 + ...queryOpts, 888 + queryFn: async ({ queryKey }) => { 889 + const { data } = await uploadFile({ 890 + ...queryKey[0].params, 891 + throwOnError: true 892 + }); 893 + return data; 894 + }, 895 + queryKey: [ 896 + { 897 + scope: 'uploadFile', 898 + params: { 899 + body: options.body, 900 + headers: options.headers, 901 + path: options.path, 902 + query: options.query 903 + } 904 + } 905 + ] 184 906 }); }; 185 907 186 - export const fileResponseOptions = () => { return queryOptions({ 187 - queryFn: fileResponse, 188 - queryKey: ['foo'] 908 + /** 909 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 910 + */ 911 + export const fileResponseOptions = (options: Options<FileResponseData>, queryOpts?: object) => { return queryOptions({ 912 + ...queryOpts, 913 + queryFn: async ({ queryKey }) => { 914 + const { data } = await fileResponse({ 915 + ...queryKey[0].params, 916 + throwOnError: true 917 + }); 918 + return data; 919 + }, 920 + queryKey: [ 921 + { 922 + scope: 'fileResponse', 923 + params: { 924 + body: options.body, 925 + headers: options.headers, 926 + path: options.path, 927 + query: options.query 928 + } 929 + } 930 + ] 189 931 }); }; 190 932 191 - export const complexTypesOptions = () => { return queryOptions({ 192 - queryFn: complexTypes, 193 - queryKey: ['foo'] 933 + /** 934 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 935 + */ 936 + export const complexTypesOptions = (options: Options<ComplexTypesData>, queryOpts?: object) => { return queryOptions({ 937 + ...queryOpts, 938 + queryFn: async ({ queryKey }) => { 939 + const { data } = await complexTypes({ 940 + ...queryKey[0].params, 941 + throwOnError: true 942 + }); 943 + return data; 944 + }, 945 + queryKey: [ 946 + { 947 + scope: 'complexTypes', 948 + params: { 949 + body: options.body, 950 + headers: options.headers, 951 + path: options.path, 952 + query: options.query 953 + } 954 + } 955 + ] 194 956 }); }; 195 957 196 - export const multipartRequestOptions = () => { return queryOptions({ 197 - queryFn: multipartRequest, 198 - queryKey: ['foo'] 958 + /** 959 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 960 + */ 961 + export const multipartRequestOptions = (options?: Options<MultipartRequestData>, queryOpts?: object) => { return queryOptions({ 962 + ...queryOpts, 963 + queryFn: async ({ queryKey }) => { 964 + const { data } = await multipartRequest({ 965 + ...queryKey[0].params, 966 + throwOnError: true 967 + }); 968 + return data; 969 + }, 970 + queryKey: [ 971 + { 972 + scope: 'multipartRequest', 973 + params: { 974 + body: options?.body, 975 + headers: options?.headers, 976 + path: options?.path, 977 + query: options?.query 978 + } 979 + } 980 + ] 199 981 }); }; 200 982 201 - export const multipartResponseOptions = () => { return queryOptions({ 202 - queryFn: multipartResponse, 203 - queryKey: ['foo'] 983 + /** 984 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 985 + */ 986 + export const multipartResponseOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 987 + ...queryOpts, 988 + queryFn: async ({ queryKey }) => { 989 + const { data } = await multipartResponse({ 990 + ...queryKey[0].params, 991 + throwOnError: true 992 + }); 993 + return data; 994 + }, 995 + queryKey: [ 996 + { 997 + scope: 'multipartResponse', 998 + params: { 999 + body: options?.body, 1000 + headers: options?.headers, 1001 + path: options?.path, 1002 + query: options?.query 1003 + } 1004 + } 1005 + ] 204 1006 }); }; 205 1007 206 - export const complexParamsOptions = () => { return queryOptions({ 207 - queryFn: complexParams, 208 - queryKey: ['foo'] 1008 + /** 1009 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 1010 + */ 1011 + export const complexParamsOptions = (options: Options<ComplexParamsData>, queryOpts?: object) => { return queryOptions({ 1012 + ...queryOpts, 1013 + queryFn: async ({ queryKey }) => { 1014 + const { data } = await complexParams({ 1015 + ...queryKey[0].params, 1016 + throwOnError: true 1017 + }); 1018 + return data; 1019 + }, 1020 + queryKey: [ 1021 + { 1022 + scope: 'complexParams', 1023 + params: { 1024 + body: options.body, 1025 + headers: options.headers, 1026 + path: options.path, 1027 + query: options.query 1028 + } 1029 + } 1030 + ] 209 1031 }); }; 210 1032 211 - export const callWithResultFromHeaderOptions = () => { return queryOptions({ 212 - queryFn: callWithResultFromHeader, 213 - queryKey: ['foo'] 1033 + /** 1034 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 1035 + */ 1036 + export const callWithResultFromHeaderOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 1037 + ...queryOpts, 1038 + queryFn: async ({ queryKey }) => { 1039 + const { data } = await callWithResultFromHeader({ 1040 + ...queryKey[0].params, 1041 + throwOnError: true 1042 + }); 1043 + return data; 1044 + }, 1045 + queryKey: [ 1046 + { 1047 + scope: 'callWithResultFromHeader', 1048 + params: { 1049 + body: options?.body, 1050 + headers: options?.headers, 1051 + path: options?.path, 1052 + query: options?.query 1053 + } 1054 + } 1055 + ] 214 1056 }); }; 215 1057 216 - export const testErrorCodeOptions = () => { return queryOptions({ 217 - queryFn: testErrorCode, 218 - queryKey: ['foo'] 1058 + /** 1059 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 1060 + */ 1061 + export const testErrorCodeOptions = (options: Options<TestErrorCodeData>, queryOpts?: object) => { return queryOptions({ 1062 + ...queryOpts, 1063 + queryFn: async ({ queryKey }) => { 1064 + const { data } = await testErrorCode({ 1065 + ...queryKey[0].params, 1066 + throwOnError: true 1067 + }); 1068 + return data; 1069 + }, 1070 + queryKey: [ 1071 + { 1072 + scope: 'testErrorCode', 1073 + params: { 1074 + body: options.body, 1075 + headers: options.headers, 1076 + path: options.path, 1077 + query: options.query 1078 + } 1079 + } 1080 + ] 219 1081 }); }; 220 1082 221 - export const nonAsciiæøåÆøÅöôêÊ字符串Options = () => { return queryOptions({ 222 - queryFn: nonAsciiæøåÆøÅöôêÊ字符串, 223 - queryKey: ['foo'] 1083 + /** 1084 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 1085 + */ 1086 + export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options<NonAsciiæøåÆøÅöôêÊ字符串Data>, queryOpts?: object) => { return queryOptions({ 1087 + ...queryOpts, 1088 + queryFn: async ({ queryKey }) => { 1089 + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ 1090 + ...queryKey[0].params, 1091 + throwOnError: true 1092 + }); 1093 + return data; 1094 + }, 1095 + queryKey: [ 1096 + { 1097 + scope: 'nonAsciiæøåÆøÅöôêÊ字符串', 1098 + params: { 1099 + body: options.body, 1100 + headers: options.headers, 1101 + path: options.path, 1102 + query: options.query 1103 + } 1104 + } 1105 + ] 224 1106 }); }; 225 1107 226 - export const putWithFormUrlEncodedOptions = () => { return queryOptions({ 227 - queryFn: putWithFormUrlEncoded, 228 - queryKey: ['foo'] 1108 + /** 1109 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 1110 + */ 1111 + export const putWithFormUrlEncodedOptions = (options: Options<PutWithFormUrlEncodedData>, queryOpts?: object) => { return queryOptions({ 1112 + ...queryOpts, 1113 + queryFn: async ({ queryKey }) => { 1114 + const { data } = await putWithFormUrlEncoded({ 1115 + ...queryKey[0].params, 1116 + throwOnError: true 1117 + }); 1118 + return data; 1119 + }, 1120 + queryKey: [ 1121 + { 1122 + scope: 'putWithFormUrlEncoded', 1123 + params: { 1124 + body: options.body, 1125 + headers: options.headers, 1126 + path: options.path, 1127 + query: options.query 1128 + } 1129 + } 1130 + ] 229 1131 }); };
+139 -18
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch_plugin_tanstack-react-query_transform/tanstack-query.gen.ts.snap
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { Options } from '@hey-api/client-fetch'; 3 4 import { queryOptions } from '@tanstack/react-query'; 4 5 import { parentModelWithDates, modelWithDates, modelWithDatesArray, arrayOfDates, date, multipleResponses } from './services.gen'; 5 6 6 - export const parentModelWithDatesOptions = () => { return queryOptions({ 7 - queryFn: parentModelWithDates, 8 - queryKey: ['foo'] 7 + /** 8 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 9 + */ 10 + export const parentModelWithDatesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 11 + ...queryOpts, 12 + queryFn: async ({ queryKey }) => { 13 + const { data } = await parentModelWithDates({ 14 + ...queryKey[0].params, 15 + throwOnError: true 16 + }); 17 + return data; 18 + }, 19 + queryKey: [ 20 + { 21 + scope: 'parentModelWithDates', 22 + params: { 23 + body: options?.body, 24 + headers: options?.headers, 25 + path: options?.path, 26 + query: options?.query 27 + } 28 + } 29 + ] 9 30 }); }; 10 31 11 - export const modelWithDatesOptions = () => { return queryOptions({ 12 - queryFn: modelWithDates, 13 - queryKey: ['foo'] 32 + /** 33 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 34 + */ 35 + export const modelWithDatesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 36 + ...queryOpts, 37 + queryFn: async ({ queryKey }) => { 38 + const { data } = await modelWithDates({ 39 + ...queryKey[0].params, 40 + throwOnError: true 41 + }); 42 + return data; 43 + }, 44 + queryKey: [ 45 + { 46 + scope: 'modelWithDates', 47 + params: { 48 + body: options?.body, 49 + headers: options?.headers, 50 + path: options?.path, 51 + query: options?.query 52 + } 53 + } 54 + ] 14 55 }); }; 15 56 16 - export const modelWithDatesArrayOptions = () => { return queryOptions({ 17 - queryFn: modelWithDatesArray, 18 - queryKey: ['foo'] 57 + /** 58 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 59 + */ 60 + export const modelWithDatesArrayOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 61 + ...queryOpts, 62 + queryFn: async ({ queryKey }) => { 63 + const { data } = await modelWithDatesArray({ 64 + ...queryKey[0].params, 65 + throwOnError: true 66 + }); 67 + return data; 68 + }, 69 + queryKey: [ 70 + { 71 + scope: 'modelWithDatesArray', 72 + params: { 73 + body: options?.body, 74 + headers: options?.headers, 75 + path: options?.path, 76 + query: options?.query 77 + } 78 + } 79 + ] 19 80 }); }; 20 81 21 - export const arrayOfDatesOptions = () => { return queryOptions({ 22 - queryFn: arrayOfDates, 23 - queryKey: ['foo'] 82 + /** 83 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 84 + */ 85 + export const arrayOfDatesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 86 + ...queryOpts, 87 + queryFn: async ({ queryKey }) => { 88 + const { data } = await arrayOfDates({ 89 + ...queryKey[0].params, 90 + throwOnError: true 91 + }); 92 + return data; 93 + }, 94 + queryKey: [ 95 + { 96 + scope: 'arrayOfDates', 97 + params: { 98 + body: options?.body, 99 + headers: options?.headers, 100 + path: options?.path, 101 + query: options?.query 102 + } 103 + } 104 + ] 24 105 }); }; 25 106 26 - export const dateOptions = () => { return queryOptions({ 27 - queryFn: date, 28 - queryKey: ['foo'] 107 + /** 108 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 109 + */ 110 + export const dateOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 111 + ...queryOpts, 112 + queryFn: async ({ queryKey }) => { 113 + const { data } = await date({ 114 + ...queryKey[0].params, 115 + throwOnError: true 116 + }); 117 + return data; 118 + }, 119 + queryKey: [ 120 + { 121 + scope: 'date', 122 + params: { 123 + body: options?.body, 124 + headers: options?.headers, 125 + path: options?.path, 126 + query: options?.query 127 + } 128 + } 129 + ] 29 130 }); }; 30 131 31 - export const multipleResponsesOptions = () => { return queryOptions({ 32 - queryFn: multipleResponses, 33 - queryKey: ['foo'] 132 + /** 133 + * TODO: describe arguments, options is Hey API, queryOpts is TanStack Query 134 + */ 135 + export const multipleResponsesOptions = (options?: Options, queryOpts?: object) => { return queryOptions({ 136 + ...queryOpts, 137 + queryFn: async ({ queryKey }) => { 138 + const { data } = await multipleResponses({ 139 + ...queryKey[0].params, 140 + throwOnError: true 141 + }); 142 + return data; 143 + }, 144 + queryKey: [ 145 + { 146 + scope: 'multipleResponses', 147 + params: { 148 + body: options?.body, 149 + headers: options?.headers, 150 + path: options?.path, 151 + query: options?.query 152 + } 153 + } 154 + ] 34 155 }); };