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 #2218 from hey-api/feat/tanstack-query-api

feat(tanstack-query): add name and case options

authored by

Lubos and committed by
GitHub
a6eacf0c 4d43c099

+1588 -426
+15
.changeset/polite-pots-watch.md
··· 1 + --- 2 + '@hey-api/openapi-ts': minor 3 + --- 4 + 5 + feat(tanstack-query): add name and case options 6 + 7 + ### Updated TanStack Query options 8 + 9 + The TanStack Query plugin options have been expanded to support more naming and casing patterns. As a result, the following options have been renamed. 10 + 11 + - `queryOptionsNameBuilder` renamed to `queryOptions` 12 + - `infiniteQueryOptionsNameBuilder` renamed to `infiniteQueryOptions` 13 + - `mutationOptionsNameBuilder` renamed to `mutationOptions` 14 + - `queryKeyNameBuilder` renamed to `queryKeys` 15 + - `infiniteQueryKeyNameBuilder` renamed to `infiniteQueryKeys`
+10
docs/openapi-ts/migrating.md
··· 29 29 30 30 ## v0.75.0 31 31 32 + ### Updated TanStack Query options 33 + 34 + The TanStack Query plugin options have been expanded to support more naming and casing patterns. As a result, the following options have been renamed. 35 + 36 + - `queryOptionsNameBuilder` renamed to `queryOptions` 37 + - `infiniteQueryOptionsNameBuilder` renamed to `infiniteQueryOptions` 38 + - `mutationOptionsNameBuilder` renamed to `mutationOptions` 39 + - `queryKeyNameBuilder` renamed to `queryKeys` 40 + - `infiniteQueryKeyNameBuilder` renamed to `infiniteQueryKeys` 41 + 32 42 ### Added `plugin.forEach()` method 33 43 34 44 This method replaces the `.subscribe()` method. Additionally, `.forEach()` is executed immediately, which means we don't need the `before` and `after` events – simply move your code before and after the `.forEach()` block.
+54 -40
docs/openapi-ts/plugins/tanstack-query.md
··· 37 37 ::: code-group 38 38 39 39 ```js [react] 40 - import { defaultPlugins } from '@hey-api/openapi-ts'; 41 - 42 40 export default { 43 41 input: 'https://get.heyapi.dev/hey-api/backend', 44 42 output: 'src/client', 45 43 plugins: [ 46 - ...defaultPlugins, 44 + // ...other plugins 47 45 '@tanstack/react-query', // [!code ++] 48 46 ], 49 47 }; 50 48 ``` 51 49 52 50 ```js [vue] 53 - import { defaultPlugins } from '@hey-api/openapi-ts'; 54 - 55 51 export default { 56 52 input: 'https://get.heyapi.dev/hey-api/backend', 57 53 output: 'src/client', 58 54 plugins: [ 59 - ...defaultPlugins, 55 + // ...other plugins 60 56 '@tanstack/vue-query', // [!code ++] 61 57 ], 62 58 }; 63 59 ``` 64 60 65 61 ```js [angular] 66 - import { defaultPlugins } from '@hey-api/openapi-ts'; 67 - 68 62 export default { 69 63 input: 'https://get.heyapi.dev/hey-api/backend', 70 64 output: 'src/client', 71 65 plugins: [ 72 - ...defaultPlugins, 66 + // ...other plugins 73 67 '@tanstack/angular-query-experimental', // [!code ++] 74 68 ], 75 69 }; 76 70 ``` 77 71 78 72 ```js [svelte] 79 - import { defaultPlugins } from '@hey-api/openapi-ts'; 80 - 81 73 export default { 82 74 input: 'https://get.heyapi.dev/hey-api/backend', 83 75 output: 'src/client', 84 76 plugins: [ 85 - ...defaultPlugins, 77 + // ...other plugins 86 78 '@tanstack/svelte-query', // [!code ++] 87 79 ], 88 80 }; 89 81 ``` 90 82 91 83 ```js [solid] 92 - import { defaultPlugins } from '@hey-api/openapi-ts'; 93 - 94 84 export default { 95 85 input: 'https://get.heyapi.dev/hey-api/backend', 96 86 output: 'src/client', 97 87 plugins: [ 98 - ...defaultPlugins, 88 + // ...other plugins 99 89 '@tanstack/solid-query', // [!code ++] 100 90 ], 101 91 }; ··· 121 111 }); 122 112 ``` 123 113 124 - You can customize query function names using `queryOptionsNameBuilder`. 114 + You can customize the naming and casing pattern for query options functions using the `queryOptions.name` and `queryOptions.case` options. 115 + 116 + ## Query Keys 117 + 118 + If you have access to the result of query options function, you can get the query key from the `queryKey` field. 119 + 120 + ```ts 121 + const { queryKey } = getPetByIdOptions({ 122 + path: { 123 + petId: 1, 124 + }, 125 + }); 126 + ``` 127 + 128 + Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `QueryKey`, e.g. `getPetByIdQueryKey()`. 129 + 130 + ```ts 131 + const queryKey = getPetByIdQueryKey({ 132 + path: { 133 + petId: 1, 134 + }, 135 + }); 136 + ``` 137 + 138 + You can customize the naming and casing pattern for query key functions using the `queryKeys.name` and `queryKeys.case` options. 125 139 126 140 ## Infinite Queries 127 141 ··· 139 153 }); 140 154 ``` 141 155 142 - You can customize infinite query function names using `infiniteQueryOptionsNameBuilder`. 156 + You can customize the naming and casing pattern for infinite query options functions using the `infiniteQueryOptions.name` and `infiniteQueryOptions.case` options. 143 157 144 - ## Mutations 158 + ## Infinite Query Keys 145 159 146 - Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`. 160 + If you have access to the result of infinite query options function, you can get the query key from the `queryKey` field. 147 161 148 162 ```ts 149 - const addPet = useMutation({ 150 - ...addPetMutation(), 151 - onError: (error) => { 152 - console.log(error); 163 + const { queryKey } = getPetByIdInfiniteOptions({ 164 + path: { 165 + petId: 1, 153 166 }, 154 167 }); 168 + ``` 155 169 156 - addPet.mutate({ 157 - body: { 158 - name: 'Kitty', 170 + Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `InfiniteQueryKey`, e.g. `getPetByIdInfiniteQueryKey()`. 171 + 172 + ```ts 173 + const queryKey = getPetByIdInfiniteQueryKey({ 174 + path: { 175 + petId: 1, 159 176 }, 160 177 }); 161 178 ``` 162 179 163 - You can customize mutation function names using `mutationOptionsNameBuilder`. 180 + You can customize the naming and casing pattern for infinite query key functions using the `infiniteQueryKeys.name` and `infiniteQueryKeys.case` options. 164 181 165 - ## Query Keys 182 + ## Mutations 166 183 167 - Query keys are generated for both queries and infinite queries. If you have access to the result of query or infinite query options function, you can get the query key from the `queryKey` field. 184 + Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`. 168 185 169 186 ```ts 170 - const { queryKey } = getPetByIdOptions({ 171 - path: { 172 - petId: 1, 187 + const addPet = useMutation({ 188 + ...addPetMutation(), 189 + onError: (error) => { 190 + console.log(error); 173 191 }, 174 192 }); 175 - ``` 176 193 177 - Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `QueryKey` or `InfiniteQueryKey`, e.g. `getPetByIdQueryKey()` or `getPetByIdInfiniteQueryKey()`. 178 - 179 - ```ts 180 - const queryKey = getPetByIdQueryKey({ 181 - path: { 182 - petId: 1, 194 + addPet.mutate({ 195 + body: { 196 + name: 'Kitty', 183 197 }, 184 198 }); 185 199 ``` 186 200 187 - You can customize query key function names using `queryKeyNameBuilder` and `infiniteQueryKeyNameBuilder`. 201 + You can customize the naming and casing pattern for mutation options functions using the `mutationOptions.name` and `mutationOptions.case` options. 188 202 189 203 <!--@include: ../../examples.md--> 190 204 <!--@include: ../../sponsors.md-->
+20 -8
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 60 60 // 'invalid', 61 61 // 'servers-entry.yaml', 62 62 // ), 63 - // path: path.resolve(__dirname, 'spec', '3.1.x', 'validators.yaml'), 64 - path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 63 + path: path.resolve(__dirname, 'spec', '3.1.x', 'full.yaml'), 64 + // path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 65 65 // path: 'http://localhost:4000/', 66 66 // path: 'https://get.heyapi.dev/', 67 67 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', ··· 150 150 // name: 'fastify', 151 151 }, 152 152 { 153 + // case: 'SCREAMING_SNAKE_CASE', 154 + // comments: false, 153 155 exportFromIndex: true, 154 - infiniteQueryKeyNameBuilder: '{{name}}IQK', 155 - infiniteQueryOptionsNameBuilder: '{{name}}InfiniteQuery', 156 - mutationOptionsNameBuilder: '{{name}}MutationOptions', 157 - // name: '@tanstack/react-query', 158 - queryKeyNameBuilder: '{{name}}QK', 159 - queryOptionsNameBuilder: '{{name}}Query', 156 + // infiniteQueryKeys: { 157 + // name: '{{name}}IQK', 158 + // }, 159 + // infiniteQueryOptions: { 160 + // name: '{{name}}IQO', 161 + // }, 162 + // mutationOptions: { 163 + // name: '{{name}}MO', 164 + // }, 165 + name: '@tanstack/react-query', 166 + // queryKeys: { 167 + // name: '{{name}}QK', 168 + // }, 169 + // queryOptions: { 170 + // name: '{{name}}QO', 171 + // }, 160 172 }, 161 173 { 162 174 // comments: false,
+75 -25
packages/openapi-ts-tests/test/plugins.test.ts
··· 220 220 output: 'name-builder', 221 221 plugins: [ 222 222 { 223 - infiniteQueryKeyNameBuilder: '{{name}}A', 224 - infiniteQueryOptionsNameBuilder: '{{name}}B', 225 - mutationOptionsNameBuilder: '{{name}}C', 223 + infiniteQueryKeys: { 224 + name: '{{name}}A', 225 + }, 226 + infiniteQueryOptions: { 227 + name: '{{name}}B', 228 + }, 229 + mutationOptions: { 230 + name: '{{name}}C', 231 + }, 226 232 name: '@tanstack/angular-query-experimental', 227 - queryKeyNameBuilder: '{{name}}D', 228 - queryOptionsNameBuilder: '{{name}}E', 233 + queryKeys: { 234 + name: '{{name}}D', 235 + }, 236 + queryOptions: { 237 + name: '{{name}}E', 238 + }, 229 239 }, 230 240 '@hey-api/client-fetch', 231 241 '@hey-api/sdk', ··· 240 250 output: 'name-builder', 241 251 plugins: [ 242 252 { 243 - infiniteQueryKeyNameBuilder: '{{name}}A', 244 - infiniteQueryOptionsNameBuilder: '{{name}}B', 245 - mutationOptionsNameBuilder: '{{name}}C', 253 + infiniteQueryKeys: { 254 + name: '{{name}}A', 255 + }, 256 + infiniteQueryOptions: { 257 + name: '{{name}}B', 258 + }, 259 + mutationOptions: { 260 + name: '{{name}}C', 261 + }, 246 262 name: '@tanstack/react-query', 247 - queryKeyNameBuilder: '{{name}}D', 248 - queryOptionsNameBuilder: '{{name}}E', 263 + queryKeys: { 264 + name: '{{name}}D', 265 + }, 266 + queryOptions: { 267 + name: '{{name}}E', 268 + }, 249 269 }, 250 270 '@hey-api/client-fetch', 251 271 '@hey-api/sdk', ··· 260 280 output: 'name-builder', 261 281 plugins: [ 262 282 { 263 - infiniteQueryKeyNameBuilder: '{{name}}A', 264 - infiniteQueryOptionsNameBuilder: '{{name}}B', 265 - mutationOptionsNameBuilder: '{{name}}C', 283 + infiniteQueryKeys: { 284 + name: '{{name}}A', 285 + }, 286 + infiniteQueryOptions: { 287 + name: '{{name}}B', 288 + }, 289 + mutationOptions: { 290 + name: '{{name}}C', 291 + }, 266 292 name: '@tanstack/solid-query', 267 - queryKeyNameBuilder: '{{name}}D', 268 - queryOptionsNameBuilder: '{{name}}E', 293 + queryKeys: { 294 + name: '{{name}}D', 295 + }, 296 + queryOptions: { 297 + name: '{{name}}E', 298 + }, 269 299 }, 270 300 '@hey-api/client-fetch', 271 301 '@hey-api/sdk', ··· 280 310 output: 'name-builder', 281 311 plugins: [ 282 312 { 283 - infiniteQueryKeyNameBuilder: '{{name}}A', 284 - infiniteQueryOptionsNameBuilder: '{{name}}B', 285 - mutationOptionsNameBuilder: '{{name}}C', 313 + infiniteQueryKeys: { 314 + name: '{{name}}A', 315 + }, 316 + infiniteQueryOptions: { 317 + name: '{{name}}B', 318 + }, 319 + mutationOptions: { 320 + name: '{{name}}C', 321 + }, 286 322 name: '@tanstack/svelte-query', 287 - queryKeyNameBuilder: '{{name}}D', 288 - queryOptionsNameBuilder: '{{name}}E', 323 + queryKeys: { 324 + name: '{{name}}D', 325 + }, 326 + queryOptions: { 327 + name: '{{name}}E', 328 + }, 289 329 }, 290 330 '@hey-api/client-fetch', 291 331 '@hey-api/sdk', ··· 300 340 output: 'name-builder', 301 341 plugins: [ 302 342 { 303 - infiniteQueryKeyNameBuilder: '{{name}}A', 304 - infiniteQueryOptionsNameBuilder: '{{name}}B', 305 - mutationOptionsNameBuilder: '{{name}}C', 343 + infiniteQueryKeys: { 344 + name: '{{name}}A', 345 + }, 346 + infiniteQueryOptions: { 347 + name: '{{name}}B', 348 + }, 349 + mutationOptions: { 350 + name: '{{name}}C', 351 + }, 306 352 name: '@tanstack/vue-query', 307 - queryKeyNameBuilder: '{{name}}D', 308 - queryOptionsNameBuilder: '{{name}}E', 353 + queryKeys: { 354 + name: '{{name}}D', 355 + }, 356 + queryOptions: { 357 + name: '{{name}}E', 358 + }, 309 359 }, 310 360 '@hey-api/client-fetch', 311 361 '@hey-api/sdk',
+73 -4
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 2 import type { Plugin } from '../../types'; 3 - import { defaultTanStackQueryConfig } from '../query-core/config'; 4 3 import { handler } from '../query-core/plugin'; 5 4 import { handlerLegacy } from '../query-core/plugin-legacy'; 6 - import type { Config } from './types'; 5 + import type { Config, ResolvedConfig } from './types'; 7 6 8 - export const defaultConfig: Plugin.Config<Config> = { 9 - config: defaultTanStackQueryConfig, 7 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 8 + config: { 9 + case: 'camelCase', 10 + comments: true, 11 + exportFromIndex: false, 12 + }, 10 13 dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 14 handler, 12 15 handlerLegacy, 13 16 name: '@tanstack/angular-query-experimental', 14 17 output: '@tanstack/angular-query-experimental', 18 + resolveConfig: (plugin, context) => { 19 + plugin.config.infiniteQueryKeys = context.valueToObject({ 20 + defaultValue: { 21 + case: plugin.config.case ?? 'camelCase', 22 + enabled: true, 23 + name: '{{name}}InfiniteQueryKey', 24 + }, 25 + mappers: { 26 + boolean: (enabled) => ({ enabled }), 27 + string: (name) => ({ enabled: true, name }), 28 + }, 29 + value: plugin.config.infiniteQueryKeys, 30 + }); 31 + 32 + plugin.config.infiniteQueryOptions = context.valueToObject({ 33 + defaultValue: { 34 + case: plugin.config.case ?? 'camelCase', 35 + enabled: true, 36 + name: '{{name}}InfiniteOptions', 37 + }, 38 + mappers: { 39 + boolean: (enabled) => ({ enabled }), 40 + string: (name) => ({ enabled: true, name }), 41 + }, 42 + value: plugin.config.infiniteQueryOptions, 43 + }); 44 + 45 + plugin.config.mutationOptions = context.valueToObject({ 46 + defaultValue: { 47 + case: plugin.config.case ?? 'camelCase', 48 + enabled: true, 49 + name: '{{name}}Mutation', 50 + }, 51 + mappers: { 52 + boolean: (enabled) => ({ enabled }), 53 + string: (name) => ({ enabled: true, name }), 54 + }, 55 + value: plugin.config.mutationOptions, 56 + }); 57 + 58 + plugin.config.queryKeys = context.valueToObject({ 59 + defaultValue: { 60 + case: plugin.config.case ?? 'camelCase', 61 + enabled: true, 62 + name: '{{name}}QueryKey', 63 + }, 64 + mappers: { 65 + boolean: (enabled) => ({ enabled }), 66 + string: (name) => ({ enabled: true, name }), 67 + }, 68 + value: plugin.config.queryKeys, 69 + }); 70 + 71 + plugin.config.queryOptions = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'camelCase', 74 + enabled: true, 75 + name: '{{name}}Options', 76 + }, 77 + mappers: { 78 + boolean: (enabled) => ({ enabled }), 79 + string: (name) => ({ enabled: true, name }), 80 + }, 81 + value: plugin.config.queryOptions, 82 + }); 83 + }, 15 84 }; 16 85 17 86 /**
+152 -11
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.d.ts
··· 1 + import type { StringCase } from '../../../types/config'; 1 2 import type { Plugin } from '../../types'; 2 - import type { TanStackQuery } from '../query-core/types'; 3 3 4 4 export interface Config 5 - extends Plugin.Name<'@tanstack/angular-query-experimental'>, 6 - TanStackQuery.Config { 5 + extends Plugin.Name<'@tanstack/angular-query-experimental'> { 6 + /** 7 + * The casing convention to use for generated names. 8 + * 9 + * @default 'camelCase' 10 + */ 11 + case?: StringCase; 7 12 /** 8 - * Generate {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 13 + * Add comments from SDK functions to the generated TanStack Query code? 9 14 * 10 15 * @default true 11 16 */ 12 - infiniteQueryOptions?: boolean; 17 + comments?: boolean; 18 + /** 19 + * Should the exports from the generated files be re-exported in the index barrel file? 20 + * 21 + * @default false 22 + */ 23 + exportFromIndex?: boolean; 13 24 /** 14 - * Generate {@link https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation `useMutation()`} helpers? These will be generated from DELETE, PATCH, POST, and PUT requests. 25 + * Configuration for generated infinite query key helpers. 15 26 * 16 - * @default true 27 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 17 28 */ 18 - mutationOptions?: boolean; 29 + infiniteQueryKeys?: 30 + | boolean 31 + | string 32 + | { 33 + case?: StringCase; 34 + enabled?: boolean; 35 + name?: string | ((name: string) => string); 36 + }; 37 + /** 38 + * Configuration for generated infinite query options helpers. 39 + * 40 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 41 + */ 42 + infiniteQueryOptions?: 43 + | boolean 44 + | string 45 + | { 46 + case?: StringCase; 47 + enabled?: boolean; 48 + name?: string | ((name: string) => string); 49 + }; 50 + /** 51 + * Configuration for generated mutation options helpers. 52 + * 53 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation} 54 + */ 55 + mutationOptions?: 56 + | boolean 57 + | string 58 + | { 59 + case?: StringCase; 60 + enabled?: boolean; 61 + name?: string | ((name: string) => string); 62 + }; 19 63 /** 20 64 * Name of the generated file. 21 65 * ··· 23 67 */ 24 68 output?: string; 25 69 /** 26 - * Generate {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions `queryOptions()`} helpers? 27 - * These will be generated from all requests. 70 + * Configuration for generated query keys. 71 + * 72 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey} 73 + */ 74 + queryKeys?: 75 + | boolean 76 + | string 77 + | { 78 + case?: StringCase; 79 + enabled?: boolean; 80 + name?: string | ((name: string) => string); 81 + }; 82 + /** 83 + * Configuration for generated query options helpers. 84 + * 85 + * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions} 86 + */ 87 + queryOptions?: 88 + | boolean 89 + | string 90 + | { 91 + case?: StringCase; 92 + enabled?: boolean; 93 + name?: string | ((name: string) => string); 94 + }; 95 + } 96 + 97 + export interface ResolvedConfig 98 + extends Plugin.Name<'@tanstack/angular-query-experimental'> { 99 + /** 100 + * The casing convention to use for generated names. 101 + * 102 + * @default 'camelCase' 103 + */ 104 + case: StringCase; 105 + /** 106 + * Add comments from SDK functions to the generated TanStack Query code? 28 107 * 29 108 * @default true 30 109 */ 31 - queryOptions?: boolean; 110 + comments: boolean; 111 + /** 112 + * Should the exports from the generated files be re-exported in the index barrel file? 113 + * 114 + * @default false 115 + */ 116 + exportFromIndex: boolean; 117 + /** 118 + * Resolved configuration for generated infinite query key helpers. 119 + * 120 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 121 + */ 122 + infiniteQueryKeys: { 123 + case: StringCase; 124 + enabled: boolean; 125 + name: string | ((name: string) => string); 126 + }; 127 + /** 128 + * Resolved configuration for generated infinite query options helpers. 129 + * 130 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 131 + */ 132 + infiniteQueryOptions: { 133 + case: StringCase; 134 + enabled: boolean; 135 + name: string | ((name: string) => string); 136 + }; 137 + /** 138 + * Resolved configuration for generated mutation options helpers. 139 + * 140 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 141 + */ 142 + mutationOptions: { 143 + case: StringCase; 144 + enabled: boolean; 145 + name: string | ((name: string) => string); 146 + }; 147 + /** 148 + * Name of the generated file. 149 + * 150 + * @default '@tanstack/angular-query-experimental' 151 + */ 152 + output: string; 153 + /** 154 + * Resolved configuration for generated query keys. 155 + * 156 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 157 + */ 158 + queryKeys: { 159 + case: StringCase; 160 + enabled: boolean; 161 + name: string | ((name: string) => string); 162 + }; 163 + /** 164 + * Resolved configuration for generated query options helpers. 165 + * 166 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 167 + */ 168 + queryOptions: { 169 + case: StringCase; 170 + enabled: boolean; 171 + name: string | ((name: string) => string); 172 + }; 32 173 }
-12
packages/openapi-ts/src/plugins/@tanstack/query-core/config.ts
··· 1 - export const defaultTanStackQueryConfig = { 2 - comments: true, 3 - exportFromIndex: false, 4 - infiniteQueryKeyNameBuilder: '{{name}}InfiniteQueryKey', 5 - infiniteQueryOptions: true, 6 - infiniteQueryOptionsNameBuilder: '{{name}}InfiniteOptions', 7 - mutationOptions: true, 8 - mutationOptionsNameBuilder: '{{name}}Mutation', 9 - queryKeyNameBuilder: '{{name}}QueryKey', 10 - queryOptions: true, 11 - queryOptionsNameBuilder: '{{name}}Options', 12 - } as const;
+33 -44
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 5 5 import { clientApi } from '../../../generate/client'; 6 6 import { operationPagination } from '../../../ir/operation'; 7 7 import type { IR } from '../../../ir/types'; 8 - import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 9 8 import { schemaToType } from '../../@hey-api/typescript/plugin'; 10 9 import { 11 10 createOperationComment, ··· 14 13 import { 15 14 createQueryKeyFunction, 16 15 createQueryKeyType, 17 - infiniteQueryKeyFunctionIdentifier, 18 16 queryKeyName, 19 17 queryKeyStatement, 20 18 } from './queryKey'; ··· 30 28 plugin: PluginInstance; 31 29 }) => { 32 30 const file = plugin.context.file({ id: plugin.name })!; 31 + 32 + const identifierCreateInfiniteParams = file.identifier({ 33 + // TODO: refactor for better cross-plugin compatibility 34 + $ref: `#/tanstack-query-create-infinite-params/${createInfiniteParamsFn}`, 35 + case: plugin.config.case, 36 + create: true, 37 + namespace: 'value', 38 + }); 33 39 34 40 const fn = compiler.constVariable({ 35 41 expression: compiler.arrowFunction({ ··· 213 219 }, 214 220 ], 215 221 }), 216 - name: createInfiniteParamsFn, 222 + name: identifierCreateInfiniteParams.name || '', 217 223 }); 218 224 file.add(fn); 219 225 }; 220 226 221 - const infiniteQueryOptionsFunctionIdentifier = ({ 222 - operation, 223 - plugin, 224 - }: { 225 - operation: IR.OperationObject; 226 - plugin: PluginInstance; 227 - }) => { 228 - const name = serviceFunctionIdentifier({ 229 - config: plugin.context.config, 230 - id: operation.id, 231 - operation, 232 - }); 233 - 234 - let customName = ''; 235 - 236 - if (plugin.config.infiniteQueryOptionsNameBuilder) { 237 - if (typeof plugin.config.infiniteQueryOptionsNameBuilder === 'function') { 238 - customName = plugin.config.infiniteQueryOptionsNameBuilder(name); 239 - } else { 240 - customName = plugin.config.infiniteQueryOptionsNameBuilder.replace( 241 - '{{name}}', 242 - name, 243 - ); 244 - } 245 - } 246 - 247 - return customName; 248 - }; 249 - 250 227 export const createInfiniteQueryOptions = ({ 251 228 operation, 252 229 plugin, ··· 337 314 }); 338 315 file.add(node); 339 316 340 - const infiniteQueryKeyName = infiniteQueryKeyFunctionIdentifier({ 341 - operation, 342 - plugin, 343 - }); 344 - const identifierQueryKey = file.identifier({ 345 - $ref: `#/queryKey/${infiniteQueryKeyName}`, 317 + const identifierInfiniteQueryKey = file.identifier({ 318 + // TODO: refactor for better cross-plugin compatibility 319 + $ref: `#/tanstack-query-infinite-query-key/${operation.id}`, 320 + case: plugin.config.infiniteQueryKeys.case, 321 + nameTransformer: plugin.config.infiniteQueryKeys.name, 346 322 namespace: 'value', 347 323 }); 348 324 ··· 376 352 }), 377 353 }); 378 354 355 + const identifierCreateInfiniteParams = file.identifier({ 356 + // TODO: refactor for better cross-plugin compatibility 357 + $ref: `#/tanstack-query-create-infinite-params/${createInfiniteParamsFn}`, 358 + case: plugin.config.case, 359 + namespace: 'value', 360 + }); 361 + 379 362 const statements: Array<ts.Statement> = [ 380 363 compiler.constVariable({ 381 364 comment: [ ··· 420 403 }), 421 404 compiler.constVariable({ 422 405 expression: compiler.callExpression({ 423 - functionName: createInfiniteParamsFn, 406 + functionName: identifierCreateInfiniteParams.name || '', 424 407 parameters: ['queryKey', 'page'], 425 408 }), 426 409 name: 'params', ··· 446 429 ); 447 430 } 448 431 432 + const identifierInfiniteQueryOptions = file.identifier({ 433 + // TODO: refactor for better cross-plugin compatibility 434 + $ref: `#/tanstack-query-infinite-query-options/${operation.id}`, 435 + case: plugin.config.infiniteQueryOptions.case, 436 + create: true, 437 + nameTransformer: plugin.config.infiniteQueryOptions.name, 438 + namespace: 'value', 439 + }); 440 + 449 441 const statement = compiler.constVariable({ 450 442 comment: plugin.config.comments 451 443 ? createOperationComment({ operation }) ··· 496 488 { 497 489 key: 'queryKey', 498 490 value: compiler.callExpression({ 499 - functionName: identifierQueryKey.name || '', 491 + functionName: identifierInfiniteQueryKey.name || '', 500 492 parameters: ['options'], 501 493 }), 502 494 }, ··· 515 507 }), 516 508 ], 517 509 }), 518 - name: infiniteQueryOptionsFunctionIdentifier({ 519 - operation, 520 - plugin, 521 - }), 510 + name: identifierInfiniteQueryOptions.name || '', 522 511 }); 523 512 file.add(statement); 524 513 };
+11 -32
packages/openapi-ts/src/plugins/@tanstack/query-core/mutationOptions.ts
··· 2 2 3 3 import { compiler } from '../../../compiler'; 4 4 import type { IR } from '../../../ir/types'; 5 - import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 6 5 import { createOperationComment } from '../../shared/utils/operation'; 7 6 import type { PluginInstance, PluginState } from './types'; 8 7 import { useTypeData, useTypeError, useTypeResponse } from './useType'; 9 8 10 9 const mutationOptionsFn = 'mutationOptions'; 11 10 12 - const mutationOptionsFunctionIdentifier = ({ 13 - operation, 14 - plugin, 15 - }: { 16 - operation: IR.OperationObject; 17 - plugin: PluginInstance; 18 - }) => { 19 - const name = serviceFunctionIdentifier({ 20 - config: plugin.context.config, 21 - id: operation.id, 22 - operation, 23 - }); 24 - 25 - let customName = ''; 26 - 27 - if (plugin.config.mutationOptionsNameBuilder) { 28 - if (typeof plugin.config.mutationOptionsNameBuilder === 'function') { 29 - customName = plugin.config.mutationOptionsNameBuilder(name); 30 - } else { 31 - customName = plugin.config.mutationOptionsNameBuilder.replace( 32 - '{{name}}', 33 - name, 34 - ); 35 - } 36 - } 37 - 38 - return customName; 39 - }; 40 - 41 11 export const createMutationOptions = ({ 42 12 operation, 43 13 plugin, ··· 50 20 state: PluginState; 51 21 }) => { 52 22 if ( 53 - !plugin.config.mutationOptions || 23 + !plugin.config.mutationOptions.enabled || 54 24 !( 55 25 ['delete', 'patch', 'post', 'put'] as (typeof operation.method)[] 56 26 ).includes(operation.method) ··· 129 99 ); 130 100 } 131 101 102 + const identifier = file.identifier({ 103 + // TODO: refactor for better cross-plugin compatibility 104 + $ref: `#/tanstack-query-mutation-options/${operation.id}`, 105 + case: plugin.config.mutationOptions.case, 106 + create: true, 107 + nameTransformer: plugin.config.mutationOptions.name, 108 + namespace: 'value', 109 + }); 110 + 132 111 const expression = compiler.arrowFunction({ 133 112 parameters: [ 134 113 { ··· 171 150 : undefined, 172 151 exportConst: true, 173 152 expression, 174 - name: mutationOptionsFunctionIdentifier({ operation, plugin }), 153 + name: identifier.name || '', 175 154 }); 176 155 file.add(statement); 177 156
+1
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts
··· 12 12 export const handler: PluginHandler = ({ plugin }) => { 13 13 const file = plugin.createFile({ 14 14 id: plugin.name, 15 + identifierCase: plugin.config.case, 15 16 path: plugin.output, 16 17 }); 17 18
+23 -72
packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts
··· 3 3 import { hasOperationDataRequired } from '../../../ir/operation'; 4 4 import type { IR } from '../../../ir/types'; 5 5 import { getClientBaseUrlKey } from '../../@hey-api/client-core/utils'; 6 - import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 7 6 import type { PluginInstance } from './types'; 8 7 import { useTypeData } from './useType'; 9 8 ··· 22 21 const file = plugin.context.file({ id: plugin.name })!; 23 22 24 23 const identifierCreateQueryKey = file.identifier({ 25 - $ref: `#/ir/${createQueryKeyFn}`, 24 + // TODO: refactor for better cross-plugin compatibility 25 + $ref: `#/tanstack-query-create-query-key/${createQueryKeyFn}`, 26 + case: plugin.config.case, 26 27 create: true, 27 28 namespace: 'value', 28 29 }); ··· 223 224 }) => { 224 225 const file = plugin.context.file({ id: plugin.name })!; 225 226 const identifierCreateQueryKey = file.identifier({ 226 - $ref: `#/ir/${createQueryKeyFn}`, 227 + // TODO: refactor for better cross-plugin compatibility 228 + $ref: `#/tanstack-query-create-query-key/${createQueryKeyFn}`, 229 + case: plugin.config.case, 227 230 namespace: 'value', 228 231 }); 229 232 const createQueryKeyCallExpression = compiler.callExpression({ ··· 288 291 file.add(queryKeyType); 289 292 }; 290 293 291 - export const infiniteQueryKeyFunctionIdentifier = ({ 292 - operation, 293 - plugin, 294 - }: { 295 - operation: IR.OperationObject; 296 - plugin: PluginInstance; 297 - }) => { 298 - const name = serviceFunctionIdentifier({ 299 - config: plugin.context.config, 300 - id: operation.id, 301 - operation, 302 - }); 303 - 304 - let customName = ''; 305 - 306 - if (plugin.config.infiniteQueryKeyNameBuilder) { 307 - if (typeof plugin.config.infiniteQueryKeyNameBuilder === 'function') { 308 - customName = plugin.config.infiniteQueryKeyNameBuilder(name); 309 - } else { 310 - customName = plugin.config.infiniteQueryKeyNameBuilder.replace( 311 - '{{name}}', 312 - name, 313 - ); 314 - } 315 - } 316 - 317 - return customName; 318 - }; 319 - 320 - export const queryKeyFunctionIdentifier = ({ 321 - context, 322 - operation, 323 - plugin, 324 - }: { 325 - context: IR.Context; 326 - operation: IR.OperationObject; 327 - plugin: PluginInstance; 328 - }) => { 329 - const name = serviceFunctionIdentifier({ 330 - config: context.config, 331 - id: operation.id, 332 - operation, 333 - }); 334 - 335 - let customName = ''; 336 - 337 - if (plugin.config.queryKeyNameBuilder) { 338 - if (typeof plugin.config.queryKeyNameBuilder === 'function') { 339 - customName = plugin.config.queryKeyNameBuilder(name); 340 - } else { 341 - customName = plugin.config.queryKeyNameBuilder.replace('{{name}}', name); 342 - } 343 - } 344 - 345 - return customName; 346 - }; 347 - 348 294 export const queryKeyStatement = ({ 349 295 isInfinite, 350 296 operation, ··· 358 304 }) => { 359 305 const file = plugin.context.file({ id: plugin.name })!; 360 306 const typeData = useTypeData({ operation, plugin }); 361 - const name = isInfinite 362 - ? infiniteQueryKeyFunctionIdentifier({ operation, plugin }) 363 - : queryKeyFunctionIdentifier({ 364 - context: plugin.context, 365 - operation, 366 - plugin, 307 + const identifier = isInfinite 308 + ? file.identifier({ 309 + // TODO: refactor for better cross-plugin compatibility 310 + $ref: `#/tanstack-query-infinite-query-key/${operation.id}`, 311 + case: plugin.config.infiniteQueryKeys.case, 312 + create: true, 313 + nameTransformer: plugin.config.infiniteQueryKeys.name, 314 + namespace: 'value', 315 + }) 316 + : file.identifier({ 317 + // TODO: refactor for better cross-plugin compatibility 318 + $ref: `#/tanstack-query-query-key/${operation.id}`, 319 + case: plugin.config.queryKeys.case, 320 + create: true, 321 + nameTransformer: plugin.config.queryKeys.name, 322 + namespace: 'value', 367 323 }); 368 - const identifierQueryKey = file.identifier({ 369 - $ref: `#/queryKey/${name}`, 370 - create: true, 371 - namespace: 'value', 372 - }); 373 324 const statement = compiler.constVariable({ 374 325 exportConst: true, 375 326 expression: compiler.arrowFunction({ ··· 387 338 plugin, 388 339 }), 389 340 }), 390 - name: identifierQueryKey.name || '', 341 + name: identifier.name || '', 391 342 }); 392 343 return statement; 393 344 };
+14 -38
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 2 2 3 3 import { compiler } from '../../../compiler'; 4 4 import type { IR } from '../../../ir/types'; 5 - import { serviceFunctionIdentifier } from '../../@hey-api/sdk/plugin-legacy'; 6 5 import { 7 6 createOperationComment, 8 7 isOperationOptionsRequired, ··· 10 9 import { 11 10 createQueryKeyFunction, 12 11 createQueryKeyType, 13 - queryKeyFunctionIdentifier, 14 12 queryKeyStatement, 15 13 } from './queryKey'; 16 14 import type { PluginInstance, PluginState } from './types'; ··· 18 16 19 17 const queryOptionsFn = 'queryOptions'; 20 18 21 - const queryOptionsFunctionIdentifier = ({ 22 - operation, 23 - plugin, 24 - }: { 25 - operation: IR.OperationObject; 26 - plugin: PluginInstance; 27 - }) => { 28 - const name = serviceFunctionIdentifier({ 29 - config: plugin.context.config, 30 - id: operation.id, 31 - operation, 32 - }); 33 - 34 - let customName = ''; 35 - 36 - if (plugin.config.queryOptionsNameBuilder) { 37 - if (typeof plugin.config.queryOptionsNameBuilder === 'function') { 38 - customName = plugin.config.queryOptionsNameBuilder(name); 39 - } else { 40 - customName = plugin.config.queryOptionsNameBuilder.replace( 41 - '{{name}}', 42 - name, 43 - ); 44 - } 45 - } 46 - 47 - return customName; 48 - }; 49 - 50 19 export const createQueryOptions = ({ 51 20 operation, 52 21 plugin, ··· 97 66 98 67 const typeData = useTypeData({ operation, plugin }); 99 68 100 - const queryKeyName = queryKeyFunctionIdentifier({ 101 - context: plugin.context, 102 - operation, 103 - plugin, 104 - }); 105 69 const identifierQueryKey = file.identifier({ 106 - $ref: `#/queryKey/${queryKeyName}`, 70 + // TODO: refactor for better cross-plugin compatibility 71 + $ref: `#/tanstack-query-query-key/${operation.id}`, 72 + case: plugin.config.queryKeys.case, 73 + nameTransformer: plugin.config.queryKeys.name, 107 74 namespace: 'value', 108 75 }); 109 76 ··· 158 125 ); 159 126 } 160 127 128 + const identifierQueryOptions = file.identifier({ 129 + // TODO: refactor for better cross-plugin compatibility 130 + $ref: `#/tanstack-query-query-options/${operation.id}`, 131 + case: plugin.config.queryOptions.case, 132 + create: true, 133 + nameTransformer: plugin.config.queryOptions.name, 134 + namespace: 'value', 135 + }); 136 + 161 137 const statement = compiler.constVariable({ 162 138 comment: plugin.config.comments 163 139 ? createOperationComment({ operation }) ··· 210 186 }), 211 187 ], 212 188 }), 213 - name: queryOptionsFunctionIdentifier({ operation, plugin }), 189 + name: identifierQueryOptions.name || '', 214 190 // TODO: add type error 215 191 // TODO: AxiosError<PutSubmissionMetaError> 216 192 });
+15 -75
packages/openapi-ts/src/plugins/@tanstack/query-core/types.d.ts
··· 1 1 import type { ImportExportItem } from '../../../compiler/module'; 2 2 import type { Plugin } from '../../types'; 3 - import type { Config as AngularQueryConfig } from '../angular-query-experimental'; 4 - import type { Config as ReactQueryConfig } from '../react-query'; 5 - import type { Config as SolidQueryConfig } from '../solid-query'; 6 - import type { Config as SvelteQueryConfig } from '../svelte-query'; 7 - import type { Config as VueQueryConfig } from '../vue-query'; 3 + import type { ResolvedConfig as AngularQueryResolvedConfig } from '../angular-query-experimental/types'; 4 + import type { ResolvedConfig as ReactQueryResolvedConfig } from '../react-query/types'; 5 + import type { ResolvedConfig as SolidQueryResolvedConfig } from '../solid-query/types'; 6 + import type { ResolvedConfig as SvelteQueryResolvedConfig } from '../svelte-query/types'; 7 + import type { ResolvedConfig as VueQueryResolvedConfig } from '../vue-query/types'; 8 8 9 9 export type PluginHandler = Plugin.Handler< 10 - | AngularQueryConfig 11 - | ReactQueryConfig 12 - | SolidQueryConfig 13 - | SvelteQueryConfig 14 - | VueQueryConfig 10 + | AngularQueryResolvedConfig 11 + | ReactQueryResolvedConfig 12 + | SolidQueryResolvedConfig 13 + | SvelteQueryResolvedConfig 14 + | VueQueryResolvedConfig 15 15 >; 16 16 17 17 export type PluginInstance = Plugin.Instance< 18 - | AngularQueryConfig 19 - | ReactQueryConfig 20 - | SolidQueryConfig 21 - | SvelteQueryConfig 22 - | VueQueryConfig 18 + | AngularQueryResolvedConfig 19 + | ReactQueryResolvedConfig 20 + | SolidQueryResolvedConfig 21 + | SvelteQueryResolvedConfig 22 + | VueQueryResolvedConfig 23 23 >; 24 24 25 25 export interface PluginState { ··· 31 31 hasUsedQueryFn: boolean; 32 32 typeInfiniteData: ImportExportItem; 33 33 } 34 - 35 - /** 36 - * Public TanStack Query API. 37 - */ 38 - export namespace TanStackQuery { 39 - export type Config = { 40 - /** 41 - * Add comments from SDK functions to the generated TanStack Query code? 42 - * Duplicating comments this way is useful so you don't need to drill into 43 - * the underlying SDK function to learn what it does or whether it's 44 - * deprecated. You can set this option to `false` if you prefer less 45 - * comment duplication. 46 - * 47 - * @default true 48 - */ 49 - comments?: boolean; 50 - /** 51 - * Should the exports from the generated files be re-exported in the index 52 - * barrel file? 53 - * 54 - * @default false 55 - */ 56 - exportFromIndex?: boolean; 57 - /** 58 - * Customize the generated infinite query key names. The name variable is 59 - * obtained from the SDK function name. 60 - * 61 - * @default '{{name}}InfiniteQueryKey' 62 - */ 63 - infiniteQueryKeyNameBuilder?: string | ((name: string) => string); 64 - /** 65 - * Customize the generated infinite query options names. The name variable 66 - * is obtained from the SDK function name. 67 - * 68 - * @default '{{name}}InfiniteOptions' 69 - */ 70 - infiniteQueryOptionsNameBuilder?: string | ((name: string) => string); 71 - /** 72 - * Customize the generated mutation options names. The name variable is 73 - * obtained from the SDK function name. 74 - * 75 - * @default '{{name}}Mutation' 76 - */ 77 - mutationOptionsNameBuilder?: string | ((name: string) => string); 78 - /** 79 - * Customize the generated query key names. The name variable is obtained 80 - * from the SDK function name. 81 - * 82 - * @default '{{name}}QueryKey' 83 - */ 84 - queryKeyNameBuilder?: string | ((name: string) => string); 85 - /** 86 - * Customize the generated query options names. The name variable is 87 - * obtained from the SDK function name. 88 - * 89 - * @default '{{name}}Options' 90 - */ 91 - queryOptionsNameBuilder?: string | ((name: string) => string); 92 - }; 93 - }
+73 -4
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 2 import type { Plugin } from '../../types'; 3 - import { defaultTanStackQueryConfig } from '../query-core/config'; 4 3 import { handler } from '../query-core/plugin'; 5 4 import { handlerLegacy } from '../query-core/plugin-legacy'; 6 - import type { Config } from './types'; 5 + import type { Config, ResolvedConfig } from './types'; 7 6 8 - export const defaultConfig: Plugin.Config<Config> = { 9 - config: defaultTanStackQueryConfig, 7 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 8 + config: { 9 + case: 'camelCase', 10 + comments: true, 11 + exportFromIndex: false, 12 + }, 10 13 dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 14 handler, 12 15 handlerLegacy, 13 16 name: '@tanstack/react-query', 14 17 output: '@tanstack/react-query', 18 + resolveConfig: (plugin, context) => { 19 + plugin.config.infiniteQueryKeys = context.valueToObject({ 20 + defaultValue: { 21 + case: plugin.config.case ?? 'camelCase', 22 + enabled: true, 23 + name: '{{name}}InfiniteQueryKey', 24 + }, 25 + mappers: { 26 + boolean: (enabled) => ({ enabled }), 27 + string: (name) => ({ enabled: true, name }), 28 + }, 29 + value: plugin.config.infiniteQueryKeys, 30 + }); 31 + 32 + plugin.config.infiniteQueryOptions = context.valueToObject({ 33 + defaultValue: { 34 + case: plugin.config.case ?? 'camelCase', 35 + enabled: true, 36 + name: '{{name}}InfiniteOptions', 37 + }, 38 + mappers: { 39 + boolean: (enabled) => ({ enabled }), 40 + string: (name) => ({ enabled: true, name }), 41 + }, 42 + value: plugin.config.infiniteQueryOptions, 43 + }); 44 + 45 + plugin.config.mutationOptions = context.valueToObject({ 46 + defaultValue: { 47 + case: plugin.config.case ?? 'camelCase', 48 + enabled: true, 49 + name: '{{name}}Mutation', 50 + }, 51 + mappers: { 52 + boolean: (enabled) => ({ enabled }), 53 + string: (name) => ({ enabled: true, name }), 54 + }, 55 + value: plugin.config.mutationOptions, 56 + }); 57 + 58 + plugin.config.queryKeys = context.valueToObject({ 59 + defaultValue: { 60 + case: plugin.config.case ?? 'camelCase', 61 + enabled: true, 62 + name: '{{name}}QueryKey', 63 + }, 64 + mappers: { 65 + boolean: (enabled) => ({ enabled }), 66 + string: (name) => ({ enabled: true, name }), 67 + }, 68 + value: plugin.config.queryKeys, 69 + }); 70 + 71 + plugin.config.queryOptions = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'camelCase', 74 + enabled: true, 75 + name: '{{name}}Options', 76 + }, 77 + mappers: { 78 + boolean: (enabled) => ({ enabled }), 79 + string: (name) => ({ enabled: true, name }), 80 + }, 81 + value: plugin.config.queryOptions, 82 + }); 83 + }, 15 84 }; 16 85 17 86 /**
+346 -12
packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts
··· 1 + import type { StringCase } from '../../../types/config'; 1 2 import type { Plugin } from '../../types'; 2 - import type { TanStackQuery } from '../query-core/types'; 3 3 4 - export interface Config 5 - extends Plugin.Name<'@tanstack/react-query'>, 6 - TanStackQuery.Config { 4 + export interface Config extends Plugin.Name<'@tanstack/react-query'> { 5 + /** 6 + * The casing convention to use for generated names. 7 + * 8 + * @default 'camelCase' 9 + */ 10 + case?: StringCase; 7 11 /** 8 - * Generate {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 12 + * Add comments from SDK functions to the generated TanStack Query code? 13 + * Duplicating comments this way is useful so you don't need to drill into 14 + * the underlying SDK function to learn what it does or whether it's 15 + * deprecated. You can set this option to `false` if you prefer less 16 + * comment duplication. 9 17 * 10 18 * @default true 11 19 */ 12 - infiniteQueryOptions?: boolean; 20 + comments?: boolean; 21 + /** 22 + * Should the exports from the generated files be re-exported in the index 23 + * barrel file? 24 + * 25 + * @default false 26 + */ 27 + exportFromIndex?: boolean; 28 + /** 29 + * Configuration for generated infinite query key helpers. 30 + * 31 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 32 + * 33 + * Can be: 34 + * - `boolean`: Shorthand for `{ enabled: boolean }` 35 + * - `string`: Shorthand for `{ enabled: true; name: string }` 36 + * - `object`: Full configuration object 37 + */ 38 + infiniteQueryKeys?: 39 + | boolean 40 + | string 41 + | { 42 + /** 43 + * The casing convention to use for generated names. 44 + * 45 + * @default 'camelCase' 46 + */ 47 + case?: StringCase; 48 + /** 49 + * Whether to generate infinite query key helpers. 50 + * 51 + * @default true 52 + */ 53 + enabled?: boolean; 54 + /** 55 + * Custom naming pattern for generated infinite query key names. The name variable is 56 + * obtained from the SDK function name. 57 + * 58 + * @default '{{name}}InfiniteQueryKey' 59 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 60 + */ 61 + name?: string | ((name: string) => string); 62 + }; 63 + /** 64 + * Configuration for generated infinite query options helpers. 65 + * 66 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions TanStack Query: infiniteQueryOptions} 67 + * 68 + * Can be: 69 + * - `boolean`: Shorthand for `{ enabled: boolean }` 70 + * - `string`: Shorthand for `{ enabled: true; name: string }` 71 + * - `object`: Full configuration object 72 + */ 73 + infiniteQueryOptions?: 74 + | boolean 75 + | string 76 + | { 77 + /** 78 + * The casing convention to use for generated names. 79 + * 80 + * @default 'camelCase' 81 + */ 82 + case?: StringCase; 83 + /** 84 + * Whether to generate infinite query options helpers. 85 + * 86 + * @default true 87 + */ 88 + enabled?: boolean; 89 + /** 90 + * Custom naming pattern for generated infinite query options names. The name variable is 91 + * obtained from the SDK function name. 92 + * 93 + * @default '{{name}}InfiniteOptions' 94 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 95 + */ 96 + name?: string | ((name: string) => string); 97 + }; 13 98 /** 14 - * Generate {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation `useMutation()`} helpers? These will be generated from DELETE, PATCH, POST, and PUT requests. 99 + * Configuration for generated mutation options helpers. 15 100 * 16 - * @default true 101 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation TanStack Query: useMutation} 102 + * 103 + * Can be: 104 + * - `boolean`: Shorthand for `{ enabled: boolean }` 105 + * - `string`: Shorthand for `{ enabled: true; name: string }` 106 + * - `object`: Full configuration object 17 107 */ 18 - mutationOptions?: boolean; 108 + mutationOptions?: 109 + | boolean 110 + | string 111 + | { 112 + /** 113 + * The casing convention to use for generated names. 114 + * 115 + * @default 'camelCase' 116 + */ 117 + case?: StringCase; 118 + /** 119 + * Whether to generate mutation options helpers. 120 + * 121 + * @default true 122 + */ 123 + enabled?: boolean; 124 + /** 125 + * Custom naming pattern for generated mutation options names. The name variable is 126 + * obtained from the SDK function name. 127 + * 128 + * @default '{{name}}Mutation' 129 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 130 + */ 131 + name?: string | ((name: string) => string); 132 + }; 19 133 /** 20 134 * Name of the generated file. 21 135 * ··· 23 137 */ 24 138 output?: string; 25 139 /** 26 - * Generate {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions `queryOptions()`} helpers? 27 - * These will be generated from all requests. 140 + * Configuration for generated query keys. 141 + * 142 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryKey TanStack Query: queryKey} 143 + * 144 + * Can be: 145 + * - `boolean`: Shorthand for `{ enabled: boolean }` 146 + * - `string`: Shorthand for `{ enabled: true; name: string }` 147 + * - `object`: Full configuration object 148 + */ 149 + queryKeys?: 150 + | boolean 151 + | string 152 + | { 153 + /** 154 + * The casing convention to use for generated names. 155 + * 156 + * @default 'camelCase' 157 + */ 158 + case?: StringCase; 159 + /** 160 + * Whether to generate query keys. 161 + * 162 + * @default true 163 + */ 164 + enabled?: boolean; 165 + /** 166 + * Custom naming pattern for generated query key names. The name variable is 167 + * obtained from the SDK function name. 168 + * 169 + * @default '{{name}}QueryKey' 170 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 171 + */ 172 + name?: string | ((name: string) => string); 173 + }; 174 + /** 175 + * Configuration for generated query options helpers. 176 + * 177 + * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions TanStack Query: queryOptions} 178 + * 179 + * Can be: 180 + * - `boolean`: Shorthand for `{ enabled: boolean }` 181 + * - `string`: Shorthand for `{ enabled: true; name: string }` 182 + * - `object`: Full configuration object 183 + */ 184 + queryOptions?: 185 + | boolean 186 + | string 187 + | { 188 + /** 189 + * The casing convention to use for generated names. 190 + * 191 + * @default 'camelCase' 192 + */ 193 + case?: StringCase; 194 + /** 195 + * Whether to generate query options helpers. 196 + * 197 + * @default true 198 + */ 199 + enabled?: boolean; 200 + /** 201 + * Custom naming pattern for generated query options names. The name variable is 202 + * obtained from the SDK function name. 203 + * 204 + * @default '{{name}}Options' 205 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 206 + */ 207 + name?: string | ((name: string) => string); 208 + }; 209 + } 210 + 211 + export interface ResolvedConfig extends Plugin.Name<'@tanstack/react-query'> { 212 + /** 213 + * The casing convention to use for generated names. 214 + * 215 + * @default 'camelCase' 216 + */ 217 + case: StringCase; 218 + /** 219 + * Add comments from SDK functions to the generated TanStack Query code? 28 220 * 29 221 * @default true 30 222 */ 31 - queryOptions?: boolean; 223 + comments: boolean; 224 + /** 225 + * Should the exports from the generated files be re-exported in the index barrel file? 226 + * 227 + * @default false 228 + */ 229 + exportFromIndex: boolean; 230 + /** 231 + * Resolved configuration for generated infinite query key helpers. 232 + * 233 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 234 + */ 235 + infiniteQueryKeys: { 236 + /** 237 + * The casing convention to use for generated names. 238 + * 239 + * @default 'camelCase' 240 + */ 241 + case: StringCase; 242 + /** 243 + * Whether to generate infinite query key helpers. 244 + * 245 + * @default true 246 + */ 247 + enabled: boolean; 248 + /** 249 + * Custom naming pattern for generated infinite query key names. The name variable is obtained from the SDK function name. 250 + * 251 + * @default '{{name}}InfiniteQueryKey' 252 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 253 + */ 254 + name: string | ((name: string) => string); 255 + }; 256 + /** 257 + * Resolved configuration for generated infinite query options helpers. 258 + * 259 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 260 + */ 261 + infiniteQueryOptions: { 262 + /** 263 + * The casing convention to use for generated names. 264 + * 265 + * @default 'camelCase' 266 + */ 267 + case: StringCase; 268 + /** 269 + * Whether to generate infinite query options helpers. 270 + * 271 + * @default true 272 + */ 273 + enabled: boolean; 274 + /** 275 + * Custom naming pattern for generated infinite query options names. The name variable is obtained from the SDK function name. 276 + * 277 + * @default '{{name}}InfiniteOptions' 278 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 279 + */ 280 + name: string | ((name: string) => string); 281 + }; 282 + /** 283 + * Resolved configuration for generated mutation options helpers. 284 + * 285 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 286 + */ 287 + mutationOptions: { 288 + /** 289 + * The casing convention to use for generated names. 290 + * 291 + * @default 'camelCase' 292 + */ 293 + case: StringCase; 294 + /** 295 + * Whether to generate mutation options helpers. 296 + * 297 + * @default true 298 + */ 299 + enabled: boolean; 300 + /** 301 + * Custom naming pattern for generated mutation options names. The name variable is obtained from the SDK function name. 302 + * 303 + * @default '{{name}}Mutation' 304 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 305 + */ 306 + name: string | ((name: string) => string); 307 + }; 308 + /** 309 + * Name of the generated file. 310 + * 311 + * @default '@tanstack/react-query' 312 + */ 313 + output: string; 314 + /** 315 + * Resolved configuration for generated query keys. 316 + * 317 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 318 + */ 319 + queryKeys: { 320 + /** 321 + * The casing convention to use for generated names. 322 + * 323 + * @default 'camelCase' 324 + */ 325 + case: StringCase; 326 + /** 327 + * Whether to generate query keys. 328 + * 329 + * @default true 330 + */ 331 + enabled: boolean; 332 + /** 333 + * Custom naming pattern for generated query key names. The name variable is obtained from the SDK function name. 334 + * 335 + * @default '{{name}}QueryKey' 336 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 337 + */ 338 + name: string | ((name: string) => string); 339 + }; 340 + /** 341 + * Resolved configuration for generated query options helpers. 342 + * 343 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 344 + */ 345 + queryOptions: { 346 + /** 347 + * The casing convention to use for generated names. 348 + * 349 + * @default 'camelCase' 350 + */ 351 + case: StringCase; 352 + /** 353 + * Whether to generate query options helpers. 354 + * 355 + * @default true 356 + */ 357 + enabled: boolean; 358 + /** 359 + * Custom naming pattern for generated query options names. The name variable is obtained from the SDK function name. 360 + * 361 + * @default '{{name}}Options' 362 + * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 363 + */ 364 + name: string | ((name: string) => string); 365 + }; 32 366 }
+73 -4
packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 2 import type { Plugin } from '../../types'; 3 - import { defaultTanStackQueryConfig } from '../query-core/config'; 4 3 import { handler } from '../query-core/plugin'; 5 4 import { handlerLegacy } from '../query-core/plugin-legacy'; 6 - import type { Config } from './types'; 5 + import type { Config, ResolvedConfig } from './types'; 7 6 8 - export const defaultConfig: Plugin.Config<Config> = { 9 - config: defaultTanStackQueryConfig, 7 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 8 + config: { 9 + case: 'camelCase', 10 + comments: true, 11 + exportFromIndex: false, 12 + }, 10 13 dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 14 handler, 12 15 handlerLegacy, 13 16 name: '@tanstack/solid-query', 14 17 output: '@tanstack/solid-query', 18 + resolveConfig: (plugin, context) => { 19 + plugin.config.infiniteQueryKeys = context.valueToObject({ 20 + defaultValue: { 21 + case: plugin.config.case ?? 'camelCase', 22 + enabled: true, 23 + name: '{{name}}InfiniteQueryKey', 24 + }, 25 + mappers: { 26 + boolean: (enabled) => ({ enabled }), 27 + string: (name) => ({ enabled: true, name }), 28 + }, 29 + value: plugin.config.infiniteQueryKeys, 30 + }); 31 + 32 + plugin.config.infiniteQueryOptions = context.valueToObject({ 33 + defaultValue: { 34 + case: plugin.config.case ?? 'camelCase', 35 + enabled: true, 36 + name: '{{name}}InfiniteOptions', 37 + }, 38 + mappers: { 39 + boolean: (enabled) => ({ enabled }), 40 + string: (name) => ({ enabled: true, name }), 41 + }, 42 + value: plugin.config.infiniteQueryOptions, 43 + }); 44 + 45 + plugin.config.mutationOptions = context.valueToObject({ 46 + defaultValue: { 47 + case: plugin.config.case ?? 'camelCase', 48 + enabled: true, 49 + name: '{{name}}Mutation', 50 + }, 51 + mappers: { 52 + boolean: (enabled) => ({ enabled }), 53 + string: (name) => ({ enabled: true, name }), 54 + }, 55 + value: plugin.config.mutationOptions, 56 + }); 57 + 58 + plugin.config.queryKeys = context.valueToObject({ 59 + defaultValue: { 60 + case: plugin.config.case ?? 'camelCase', 61 + enabled: true, 62 + name: '{{name}}QueryKey', 63 + }, 64 + mappers: { 65 + boolean: (enabled) => ({ enabled }), 66 + string: (name) => ({ enabled: true, name }), 67 + }, 68 + value: plugin.config.queryKeys, 69 + }); 70 + 71 + plugin.config.queryOptions = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'camelCase', 74 + enabled: true, 75 + name: '{{name}}Options', 76 + }, 77 + mappers: { 78 + boolean: (enabled) => ({ enabled }), 79 + string: (name) => ({ enabled: true, name }), 80 + }, 81 + value: plugin.config.queryOptions, 82 + }); 83 + }, 15 84 }; 16 85 17 86 /**
+151 -12
packages/openapi-ts/src/plugins/@tanstack/solid-query/types.d.ts
··· 1 + import type { StringCase } from '../../../types/config'; 1 2 import type { Plugin } from '../../types'; 2 - import type { TanStackQuery } from '../query-core/types'; 3 3 4 - export interface Config 5 - extends Plugin.Name<'@tanstack/solid-query'>, 6 - TanStackQuery.Config { 4 + export interface Config extends Plugin.Name<'@tanstack/solid-query'> { 5 + /** 6 + * The casing convention to use for generated names. 7 + * 8 + * @default 'camelCase' 9 + */ 10 + case?: StringCase; 7 11 /** 8 - * Generate `createInfiniteQuery()` helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 12 + * Add comments from SDK functions to the generated TanStack Query code? 9 13 * 10 14 * @default true 11 15 */ 12 - infiniteQueryOptions?: boolean; 16 + comments?: boolean; 17 + /** 18 + * Should the exports from the generated files be re-exported in the index barrel file? 19 + * 20 + * @default false 21 + */ 22 + exportFromIndex?: boolean; 13 23 /** 14 - * Generate `createMutation()` helpers? These will be generated from DELETE, PATCH, POST, and PUT requests. 24 + * Configuration for generated infinite query key helpers. 15 25 * 16 - * @default true 26 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 17 27 */ 18 - mutationOptions?: boolean; 28 + infiniteQueryKeys?: 29 + | boolean 30 + | string 31 + | { 32 + case?: StringCase; 33 + enabled?: boolean; 34 + name?: string | ((name: string) => string); 35 + }; 36 + /** 37 + * Configuration for generated infinite query options helpers. 38 + * 39 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 40 + */ 41 + infiniteQueryOptions?: 42 + | boolean 43 + | string 44 + | { 45 + case?: StringCase; 46 + enabled?: boolean; 47 + name?: string | ((name: string) => string); 48 + }; 49 + /** 50 + * Configuration for generated mutation options helpers. 51 + * 52 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation} 53 + */ 54 + mutationOptions?: 55 + | boolean 56 + | string 57 + | { 58 + case?: StringCase; 59 + enabled?: boolean; 60 + name?: string | ((name: string) => string); 61 + }; 19 62 /** 20 63 * Name of the generated file. 21 64 * ··· 23 66 */ 24 67 output?: string; 25 68 /** 26 - * Generate {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery `createQuery()`} helpers? 27 - * These will be generated from all requests. 69 + * Configuration for generated query keys. 70 + * 71 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey} 72 + */ 73 + queryKeys?: 74 + | boolean 75 + | string 76 + | { 77 + case?: StringCase; 78 + enabled?: boolean; 79 + name?: string | ((name: string) => string); 80 + }; 81 + /** 82 + * Configuration for generated query options helpers. 83 + * 84 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery} 85 + */ 86 + queryOptions?: 87 + | boolean 88 + | string 89 + | { 90 + case?: StringCase; 91 + enabled?: boolean; 92 + name?: string | ((name: string) => string); 93 + }; 94 + } 95 + 96 + export interface ResolvedConfig extends Plugin.Name<'@tanstack/solid-query'> { 97 + /** 98 + * The casing convention to use for generated names. 99 + * 100 + * @default 'camelCase' 101 + */ 102 + case: StringCase; 103 + /** 104 + * Add comments from SDK functions to the generated TanStack Query code? 28 105 * 29 106 * @default true 30 107 */ 31 - queryOptions?: boolean; 108 + comments: boolean; 109 + /** 110 + * Should the exports from the generated files be re-exported in the index barrel file? 111 + * 112 + * @default false 113 + */ 114 + exportFromIndex: boolean; 115 + /** 116 + * Resolved configuration for generated infinite query key helpers. 117 + * 118 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 119 + */ 120 + infiniteQueryKeys: { 121 + case: StringCase; 122 + enabled: boolean; 123 + name: string | ((name: string) => string); 124 + }; 125 + /** 126 + * Resolved configuration for generated infinite query options helpers. 127 + * 128 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 129 + */ 130 + infiniteQueryOptions: { 131 + case: StringCase; 132 + enabled: boolean; 133 + name: string | ((name: string) => string); 134 + }; 135 + /** 136 + * Resolved configuration for generated mutation options helpers. 137 + * 138 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 139 + */ 140 + mutationOptions: { 141 + case: StringCase; 142 + enabled: boolean; 143 + name: string | ((name: string) => string); 144 + }; 145 + /** 146 + * Name of the generated file. 147 + * 148 + * @default '@tanstack/solid-query' 149 + */ 150 + output: string; 151 + /** 152 + * Resolved configuration for generated query keys. 153 + * 154 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 155 + */ 156 + queryKeys: { 157 + case: StringCase; 158 + enabled: boolean; 159 + name: string | ((name: string) => string); 160 + }; 161 + /** 162 + * Resolved configuration for generated query options helpers. 163 + * 164 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 165 + */ 166 + queryOptions: { 167 + case: StringCase; 168 + enabled: boolean; 169 + name: string | ((name: string) => string); 170 + }; 32 171 }
+73 -4
packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 2 import type { Plugin } from '../../types'; 3 - import { defaultTanStackQueryConfig } from '../query-core/config'; 4 3 import { handler } from '../query-core/plugin'; 5 4 import { handlerLegacy } from '../query-core/plugin-legacy'; 6 - import type { Config } from './types'; 5 + import type { Config, ResolvedConfig } from './types'; 7 6 8 - export const defaultConfig: Plugin.Config<Config> = { 9 - config: defaultTanStackQueryConfig, 7 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 8 + config: { 9 + case: 'camelCase', 10 + comments: true, 11 + exportFromIndex: false, 12 + }, 10 13 dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 14 handler, 12 15 handlerLegacy, 13 16 name: '@tanstack/svelte-query', 14 17 output: '@tanstack/svelte-query', 18 + resolveConfig: (plugin, context) => { 19 + plugin.config.infiniteQueryKeys = context.valueToObject({ 20 + defaultValue: { 21 + case: plugin.config.case ?? 'camelCase', 22 + enabled: true, 23 + name: '{{name}}InfiniteQueryKey', 24 + }, 25 + mappers: { 26 + boolean: (enabled) => ({ enabled }), 27 + string: (name) => ({ enabled: true, name }), 28 + }, 29 + value: plugin.config.infiniteQueryKeys, 30 + }); 31 + 32 + plugin.config.infiniteQueryOptions = context.valueToObject({ 33 + defaultValue: { 34 + case: plugin.config.case ?? 'camelCase', 35 + enabled: true, 36 + name: '{{name}}InfiniteOptions', 37 + }, 38 + mappers: { 39 + boolean: (enabled) => ({ enabled }), 40 + string: (name) => ({ enabled: true, name }), 41 + }, 42 + value: plugin.config.infiniteQueryOptions, 43 + }); 44 + 45 + plugin.config.mutationOptions = context.valueToObject({ 46 + defaultValue: { 47 + case: plugin.config.case ?? 'camelCase', 48 + enabled: true, 49 + name: '{{name}}Mutation', 50 + }, 51 + mappers: { 52 + boolean: (enabled) => ({ enabled }), 53 + string: (name) => ({ enabled: true, name }), 54 + }, 55 + value: plugin.config.mutationOptions, 56 + }); 57 + 58 + plugin.config.queryKeys = context.valueToObject({ 59 + defaultValue: { 60 + case: plugin.config.case ?? 'camelCase', 61 + enabled: true, 62 + name: '{{name}}QueryKey', 63 + }, 64 + mappers: { 65 + boolean: (enabled) => ({ enabled }), 66 + string: (name) => ({ enabled: true, name }), 67 + }, 68 + value: plugin.config.queryKeys, 69 + }); 70 + 71 + plugin.config.queryOptions = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'camelCase', 74 + enabled: true, 75 + name: '{{name}}Options', 76 + }, 77 + mappers: { 78 + boolean: (enabled) => ({ enabled }), 79 + string: (name) => ({ enabled: true, name }), 80 + }, 81 + value: plugin.config.queryOptions, 82 + }); 83 + }, 15 84 }; 16 85 17 86 /**
+151 -12
packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.d.ts
··· 1 + import type { StringCase } from '../../../types/config'; 1 2 import type { Plugin } from '../../types'; 2 - import type { TanStackQuery } from '../query-core/types'; 3 3 4 - export interface Config 5 - extends Plugin.Name<'@tanstack/svelte-query'>, 6 - TanStackQuery.Config { 4 + export interface Config extends Plugin.Name<'@tanstack/svelte-query'> { 5 + /** 6 + * The casing convention to use for generated names. 7 + * 8 + * @default 'camelCase' 9 + */ 10 + case?: StringCase; 7 11 /** 8 - * Generate `createInfiniteQuery()` helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 12 + * Add comments from SDK functions to the generated TanStack Query code? 9 13 * 10 14 * @default true 11 15 */ 12 - infiniteQueryOptions?: boolean; 16 + comments?: boolean; 17 + /** 18 + * Should the exports from the generated files be re-exported in the index barrel file? 19 + * 20 + * @default false 21 + */ 22 + exportFromIndex?: boolean; 13 23 /** 14 - * Generate {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createmutation `createMutation()`} helpers? These will be generated from DELETE, PATCH, POST, and PUT requests. 24 + * Configuration for generated infinite query key helpers. 15 25 * 16 - * @default true 26 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery} 17 27 */ 18 - mutationOptions?: boolean; 28 + infiniteQueryKeys?: 29 + | boolean 30 + | string 31 + | { 32 + case?: StringCase; 33 + enabled?: boolean; 34 + name?: string | ((name: string) => string); 35 + }; 36 + /** 37 + * Configuration for generated infinite query options helpers. 38 + * 39 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery} 40 + */ 41 + infiniteQueryOptions?: 42 + | boolean 43 + | string 44 + | { 45 + case?: StringCase; 46 + enabled?: boolean; 47 + name?: string | ((name: string) => string); 48 + }; 49 + /** 50 + * Configuration for generated mutation options helpers. 51 + * 52 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createMutation} 53 + */ 54 + mutationOptions?: 55 + | boolean 56 + | string 57 + | { 58 + case?: StringCase; 59 + enabled?: boolean; 60 + name?: string | ((name: string) => string); 61 + }; 19 62 /** 20 63 * Name of the generated file. 21 64 * ··· 23 66 */ 24 67 output?: string; 25 68 /** 26 - * Generate {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/functions/createquery `createQuery()`} helpers? 27 - * These will be generated from all requests. 69 + * Configuration for generated query keys. 70 + * 71 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey} 72 + */ 73 + queryKeys?: 74 + | boolean 75 + | string 76 + | { 77 + case?: StringCase; 78 + enabled?: boolean; 79 + name?: string | ((name: string) => string); 80 + }; 81 + /** 82 + * Configuration for generated query options helpers. 83 + * 84 + * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery} 85 + */ 86 + queryOptions?: 87 + | boolean 88 + | string 89 + | { 90 + case?: StringCase; 91 + enabled?: boolean; 92 + name?: string | ((name: string) => string); 93 + }; 94 + } 95 + 96 + export interface ResolvedConfig extends Plugin.Name<'@tanstack/svelte-query'> { 97 + /** 98 + * The casing convention to use for generated names. 99 + * 100 + * @default 'camelCase' 101 + */ 102 + case: StringCase; 103 + /** 104 + * Add comments from SDK functions to the generated TanStack Query code? 28 105 * 29 106 * @default true 30 107 */ 31 - queryOptions?: boolean; 108 + comments: boolean; 109 + /** 110 + * Should the exports from the generated files be re-exported in the index barrel file? 111 + * 112 + * @default false 113 + */ 114 + exportFromIndex: boolean; 115 + /** 116 + * Resolved configuration for generated infinite query key helpers. 117 + * 118 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 119 + */ 120 + infiniteQueryKeys: { 121 + case: StringCase; 122 + enabled: boolean; 123 + name: string | ((name: string) => string); 124 + }; 125 + /** 126 + * Resolved configuration for generated infinite query options helpers. 127 + * 128 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 129 + */ 130 + infiniteQueryOptions: { 131 + case: StringCase; 132 + enabled: boolean; 133 + name: string | ((name: string) => string); 134 + }; 135 + /** 136 + * Resolved configuration for generated mutation options helpers. 137 + * 138 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createMutation 139 + */ 140 + mutationOptions: { 141 + case: StringCase; 142 + enabled: boolean; 143 + name: string | ((name: string) => string); 144 + }; 145 + /** 146 + * Name of the generated file. 147 + * 148 + * @default '@tanstack/svelte-query' 149 + */ 150 + output: string; 151 + /** 152 + * Resolved configuration for generated query keys. 153 + * 154 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey 155 + */ 156 + queryKeys: { 157 + case: StringCase; 158 + enabled: boolean; 159 + name: string | ((name: string) => string); 160 + }; 161 + /** 162 + * Resolved configuration for generated query options helpers. 163 + * 164 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery 165 + */ 166 + queryOptions: { 167 + case: StringCase; 168 + enabled: boolean; 169 + name: string | ((name: string) => string); 170 + }; 32 171 }
+73 -4
packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 2 import type { Plugin } from '../../types'; 3 - import { defaultTanStackQueryConfig } from '../query-core/config'; 4 3 import { handler } from '../query-core/plugin'; 5 4 import { handlerLegacy } from '../query-core/plugin-legacy'; 6 - import type { Config } from './types'; 5 + import type { Config, ResolvedConfig } from './types'; 7 6 8 - export const defaultConfig: Plugin.Config<Config> = { 9 - config: defaultTanStackQueryConfig, 7 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 8 + config: { 9 + case: 'camelCase', 10 + comments: true, 11 + exportFromIndex: false, 12 + }, 10 13 dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 11 14 handler, 12 15 handlerLegacy, 13 16 name: '@tanstack/vue-query', 14 17 output: '@tanstack/vue-query', 18 + resolveConfig: (plugin, context) => { 19 + plugin.config.infiniteQueryKeys = context.valueToObject({ 20 + defaultValue: { 21 + case: plugin.config.case ?? 'camelCase', 22 + enabled: true, 23 + name: '{{name}}InfiniteQueryKey', 24 + }, 25 + mappers: { 26 + boolean: (enabled) => ({ enabled }), 27 + string: (name) => ({ enabled: true, name }), 28 + }, 29 + value: plugin.config.infiniteQueryKeys, 30 + }); 31 + 32 + plugin.config.infiniteQueryOptions = context.valueToObject({ 33 + defaultValue: { 34 + case: plugin.config.case ?? 'camelCase', 35 + enabled: true, 36 + name: '{{name}}InfiniteOptions', 37 + }, 38 + mappers: { 39 + boolean: (enabled) => ({ enabled }), 40 + string: (name) => ({ enabled: true, name }), 41 + }, 42 + value: plugin.config.infiniteQueryOptions, 43 + }); 44 + 45 + plugin.config.mutationOptions = context.valueToObject({ 46 + defaultValue: { 47 + case: plugin.config.case ?? 'camelCase', 48 + enabled: true, 49 + name: '{{name}}Mutation', 50 + }, 51 + mappers: { 52 + boolean: (enabled) => ({ enabled }), 53 + string: (name) => ({ enabled: true, name }), 54 + }, 55 + value: plugin.config.mutationOptions, 56 + }); 57 + 58 + plugin.config.queryKeys = context.valueToObject({ 59 + defaultValue: { 60 + case: plugin.config.case ?? 'camelCase', 61 + enabled: true, 62 + name: '{{name}}QueryKey', 63 + }, 64 + mappers: { 65 + boolean: (enabled) => ({ enabled }), 66 + string: (name) => ({ enabled: true, name }), 67 + }, 68 + value: plugin.config.queryKeys, 69 + }); 70 + 71 + plugin.config.queryOptions = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'camelCase', 74 + enabled: true, 75 + name: '{{name}}Options', 76 + }, 77 + mappers: { 78 + boolean: (enabled) => ({ enabled }), 79 + string: (name) => ({ enabled: true, name }), 80 + }, 81 + value: plugin.config.queryOptions, 82 + }); 83 + }, 15 84 }; 16 85 17 86 /**
+151 -12
packages/openapi-ts/src/plugins/@tanstack/vue-query/types.d.ts
··· 1 + import type { StringCase } from '../../../types/config'; 1 2 import type { Plugin } from '../../types'; 2 - import type { TanStackQuery } from '../query-core/types'; 3 3 4 - export interface Config 5 - extends Plugin.Name<'@tanstack/vue-query'>, 6 - TanStackQuery.Config { 4 + export interface Config extends Plugin.Name<'@tanstack/vue-query'> { 5 + /** 6 + * The casing convention to use for generated names. 7 + * 8 + * @default 'camelCase' 9 + */ 10 + case?: StringCase; 7 11 /** 8 - * Generate {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 12 + * Add comments from SDK functions to the generated TanStack Query code? 9 13 * 10 14 * @default true 11 15 */ 12 - infiniteQueryOptions?: boolean; 16 + comments?: boolean; 17 + /** 18 + * Should the exports from the generated files be re-exported in the index barrel file? 19 + * 20 + * @default false 21 + */ 22 + exportFromIndex?: boolean; 13 23 /** 14 - * Generate {@link https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation `useMutation()`} helpers? These will be generated from DELETE, PATCH, POST, and PUT requests. 24 + * Configuration for generated infinite query key helpers. 15 25 * 16 - * @default true 26 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 17 27 */ 18 - mutationOptions?: boolean; 28 + infiniteQueryKeys?: 29 + | boolean 30 + | string 31 + | { 32 + case?: StringCase; 33 + enabled?: boolean; 34 + name?: string | ((name: string) => string); 35 + }; 36 + /** 37 + * Configuration for generated infinite query options helpers. 38 + * 39 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 40 + */ 41 + infiniteQueryOptions?: 42 + | boolean 43 + | string 44 + | { 45 + case?: StringCase; 46 + enabled?: boolean; 47 + name?: string | ((name: string) => string); 48 + }; 49 + /** 50 + * Configuration for generated mutation options helpers. 51 + * 52 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation} 53 + */ 54 + mutationOptions?: 55 + | boolean 56 + | string 57 + | { 58 + case?: StringCase; 59 + enabled?: boolean; 60 + name?: string | ((name: string) => string); 61 + }; 19 62 /** 20 63 * Name of the generated file. 21 64 * ··· 23 66 */ 24 67 output?: string; 25 68 /** 26 - * Generate {@link https://tanstack.com/query/v5/docs/framework/vue/guides/query-options `queryOptions()`} helpers? 27 - * These will be generated from all requests. 69 + * Configuration for generated query keys. 70 + * 71 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey} 72 + */ 73 + queryKeys?: 74 + | boolean 75 + | string 76 + | { 77 + case?: StringCase; 78 + enabled?: boolean; 79 + name?: string | ((name: string) => string); 80 + }; 81 + /** 82 + * Configuration for generated query options helpers. 83 + * 84 + * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions} 85 + */ 86 + queryOptions?: 87 + | boolean 88 + | string 89 + | { 90 + case?: StringCase; 91 + enabled?: boolean; 92 + name?: string | ((name: string) => string); 93 + }; 94 + } 95 + 96 + export interface ResolvedConfig extends Plugin.Name<'@tanstack/vue-query'> { 97 + /** 98 + * The casing convention to use for generated names. 99 + * 100 + * @default 'camelCase' 101 + */ 102 + case: StringCase; 103 + /** 104 + * Add comments from SDK functions to the generated TanStack Query code? 28 105 * 29 106 * @default true 30 107 */ 31 - queryOptions?: boolean; 108 + comments: boolean; 109 + /** 110 + * Should the exports from the generated files be re-exported in the index barrel file? 111 + * 112 + * @default false 113 + */ 114 + exportFromIndex: boolean; 115 + /** 116 + * Resolved configuration for generated infinite query key helpers. 117 + * 118 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 119 + */ 120 + infiniteQueryKeys: { 121 + case: StringCase; 122 + enabled: boolean; 123 + name: string | ((name: string) => string); 124 + }; 125 + /** 126 + * Resolved configuration for generated infinite query options helpers. 127 + * 128 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 129 + */ 130 + infiniteQueryOptions: { 131 + case: StringCase; 132 + enabled: boolean; 133 + name: string | ((name: string) => string); 134 + }; 135 + /** 136 + * Resolved configuration for generated mutation options helpers. 137 + * 138 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 139 + */ 140 + mutationOptions: { 141 + case: StringCase; 142 + enabled: boolean; 143 + name: string | ((name: string) => string); 144 + }; 145 + /** 146 + * Name of the generated file. 147 + * 148 + * @default '@tanstack/vue-query' 149 + */ 150 + output: string; 151 + /** 152 + * Resolved configuration for generated query keys. 153 + * 154 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 155 + */ 156 + queryKeys: { 157 + case: StringCase; 158 + enabled: boolean; 159 + name: string | ((name: string) => string); 160 + }; 161 + /** 162 + * Resolved configuration for generated query options helpers. 163 + * 164 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 165 + */ 166 + queryOptions: { 167 + case: StringCase; 168 + enabled: boolean; 169 + name: string | ((name: string) => string); 170 + }; 32 171 }
+1 -1
packages/openapi-ts/src/plugins/zod/plugin.ts
··· 1170 1170 export const handler: Plugin.Handler<ResolvedConfig> = ({ plugin }) => { 1171 1171 const file = plugin.createFile({ 1172 1172 id: zodId, 1173 - identifierCase: 'camelCase', 1173 + identifierCase: plugin.config.case, 1174 1174 path: plugin.output, 1175 1175 }); 1176 1176