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 #2068 from hey-api/fix/tanstack-query-options-required-client-false

fix(tanstack-query): require options when sdk client is set to false

authored by

Lubos and committed by
GitHub
bbbc5316 6f55225f

+55 -25
+5
.changeset/flat-cycles-develop.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(tanstack-query): require options when sdk client is set to false
+1 -1
README.md
··· 206 206 - [`@tanstack/svelte-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query) 207 207 - [`@tanstack/vue-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query) 208 208 - [`fastify`](https://heyapi.dev/openapi-ts/plugins/fastify) 209 + - [`valibot`](https://heyapi.dev/openapi-ts/plugins/valibot) 209 210 - [`zod`](https://heyapi.dev/openapi-ts/plugins/zod) 210 211 211 212 ### Planned Plugins ··· 227 228 - [Supertest](https://heyapi.dev/openapi-ts/plugins/supertest) 228 229 - [SWR](https://heyapi.dev/openapi-ts/plugins/swr) 229 230 - [TypeBox](https://heyapi.dev/openapi-ts/plugins/typebox) 230 - - [Valibot](https://heyapi.dev/openapi-ts/plugins/valibot) 231 231 - [Yup](https://heyapi.dev/openapi-ts/plugins/yup) 232 232 - [Zustand](https://heyapi.dev/openapi-ts/plugins/zustand) 233 233
+3 -3
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 80 80 // type: 'json', 81 81 }, 82 82 { 83 - // asClass: true, 83 + asClass: true, 84 84 // auth: false, 85 - // client: false, 85 + client: false, 86 86 // include... 87 87 name: '@hey-api/sdk', 88 88 // operationId: false, ··· 115 115 }, 116 116 { 117 117 exportFromIndex: true, 118 - // name: '@tanstack/react-query', 118 + name: '@tanstack/react-query', 119 119 }, 120 120 { 121 121 // exportFromIndex: true,
+1 -1
packages/openapi-ts/README.md
··· 206 206 - [`@tanstack/svelte-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query) 207 207 - [`@tanstack/vue-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query) 208 208 - [`fastify`](https://heyapi.dev/openapi-ts/plugins/fastify) 209 + - [`valibot`](https://heyapi.dev/openapi-ts/plugins/valibot) 209 210 - [`zod`](https://heyapi.dev/openapi-ts/plugins/zod) 210 211 211 212 ### Planned Plugins ··· 227 228 - [Supertest](https://heyapi.dev/openapi-ts/plugins/supertest) 228 229 - [SWR](https://heyapi.dev/openapi-ts/plugins/swr) 229 230 - [TypeBox](https://heyapi.dev/openapi-ts/plugins/typebox) 230 - - [Valibot](https://heyapi.dev/openapi-ts/plugins/valibot) 231 231 - [Yup](https://heyapi.dev/openapi-ts/plugins/yup) 232 232 - [Zustand](https://heyapi.dev/openapi-ts/plugins/zustand) 233 233
+13 -9
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 4 4 import type { ObjectValue } from '../../../compiler/types'; 5 5 import { clientApi, clientModulePath } from '../../../generate/client'; 6 6 import type { TypeScriptFile } from '../../../generate/files'; 7 - import { 8 - hasOperationDataRequired, 9 - statusCodeToGroup, 10 - } from '../../../ir/operation'; 7 + import { statusCodeToGroup } from '../../../ir/operation'; 11 8 import type { IR } from '../../../ir/types'; 12 9 import { getServiceName } from '../../../utils/postprocess'; 13 10 import { transformServiceName } from '../../../utils/transform'; 14 - import { createOperationComment } from '../../shared/utils/operation'; 11 + import { 12 + createOperationComment, 13 + isOperationOptionsRequired, 14 + } from '../../shared/utils/operation'; 15 15 import type { Plugin } from '../../types'; 16 16 import { clientId, getClientPlugin } from '../client-core/utils'; 17 17 import { ··· 495 495 const sdks = new Map<string, Array<ts.MethodDeclaration>>(); 496 496 497 497 context.subscribe('operation', ({ operation }) => { 498 - const isRequiredOptions = 499 - !plugin.client || isNuxtClient || hasOperationDataRequired(operation); 498 + const isRequiredOptions = isOperationOptionsRequired({ 499 + context, 500 + operation, 501 + }); 500 502 const identifierResponse = importIdentifierResponse({ 501 503 context, 502 504 file, ··· 603 605 const file = context.file({ id: sdkId })!; 604 606 605 607 context.subscribe('operation', ({ operation }) => { 606 - const isRequiredOptions = 607 - !plugin.client || isNuxtClient || hasOperationDataRequired(operation); 608 + const isRequiredOptions = isOperationOptionsRequired({ 609 + context, 610 + operation, 611 + }); 608 612 const identifierResponse = importIdentifierResponse({ 609 613 context, 610 614 file,
+7 -7
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 3 3 import { compiler } from '../../../compiler'; 4 4 import { tsNodeToString } from '../../../compiler/utils'; 5 5 import { clientApi } from '../../../generate/client'; 6 - import { 7 - hasOperationDataRequired, 8 - operationPagination, 9 - } from '../../../ir/operation'; 6 + import { operationPagination } from '../../../ir/operation'; 10 7 import type { IR } from '../../../ir/types'; 11 8 import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 12 9 import { schemaToType } from '../../@hey-api/typescript/plugin'; 13 - import { createOperationComment } from '../../shared/utils/operation'; 10 + import { 11 + createOperationComment, 12 + isOperationOptionsRequired, 13 + } from '../../shared/utils/operation'; 14 14 import { 15 15 createQueryKeyFunction, 16 16 createQueryKeyType, ··· 253 253 } 254 254 255 255 const file = context.file({ id: plugin.name })!; 256 - const isRequired = hasOperationDataRequired(operation); 256 + const isRequiredOptions = isOperationOptionsRequired({ context, operation }); 257 257 258 258 if (!state.hasInfiniteQueries) { 259 259 state.hasInfiniteQueries = true; ··· 333 333 expression: compiler.arrowFunction({ 334 334 parameters: [ 335 335 { 336 - isRequired, 336 + isRequired: isRequiredOptions, 337 337 name: 'options', 338 338 type: typeData, 339 339 },
+6 -4
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 1 1 import { compiler } from '../../../compiler'; 2 - import { hasOperationDataRequired } from '../../../ir/operation'; 3 2 import type { IR } from '../../../ir/types'; 4 3 import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 5 - import { createOperationComment } from '../../shared/utils/operation'; 4 + import { 5 + createOperationComment, 6 + isOperationOptionsRequired, 7 + } from '../../shared/utils/operation'; 6 8 import { 7 9 createQueryKeyFunction, 8 10 createQueryKeyType, ··· 48 50 } 49 51 50 52 const file = context.file({ id: plugin.name })!; 51 - const isRequired = hasOperationDataRequired(operation); 53 + const isRequiredOptions = isOperationOptionsRequired({ context, operation }); 52 54 53 55 if (!state.hasQueries) { 54 56 state.hasQueries = true; ··· 95 97 expression: compiler.arrowFunction({ 96 98 parameters: [ 97 99 { 98 - isRequired, 100 + isRequired: isRequiredOptions, 99 101 name: 'options', 100 102 type: typeData, 101 103 },
+19
packages/openapi-ts/src/plugins/shared/utils/operation.ts
··· 1 1 import type { Comments } from '../../../compiler'; 2 + import { hasOperationDataRequired } from '../../../ir/operation'; 2 3 import type { IR } from '../../../ir/types'; 3 4 import { escapeComment } from '../../../utils/escape'; 5 + import { getClientPlugin } from '../../@hey-api/client-core/utils'; 4 6 5 7 export const createOperationComment = ({ 6 8 operation, ··· 23 25 24 26 return comments.length ? comments : undefined; 25 27 }; 28 + 29 + export const isOperationOptionsRequired = ({ 30 + context, 31 + operation, 32 + }: { 33 + context: IR.Context; 34 + operation: IR.OperationObject; 35 + }): boolean => { 36 + const client = getClientPlugin(context.config); 37 + const isNuxtClient = client.name === '@hey-api/client-nuxt'; 38 + const plugin = context.config.plugins['@hey-api/sdk']; 39 + return ( 40 + (plugin && !plugin.client) || 41 + isNuxtClient || 42 + hasOperationDataRequired(operation) 43 + ); 44 + };