@kubb/plugin-react-query 4.15.1 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/{components-B6lqcqgn.js → components-DVc9iach.js} +259 -217
  2. package/dist/components-DVc9iach.js.map +1 -0
  3. package/dist/{components-6nRaAppd.cjs → components-YtTYHVwV.cjs} +259 -217
  4. package/dist/components-YtTYHVwV.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.js +1 -1
  7. package/dist/{generators-CYoqgYAV.cjs → generators-C6VGGGTj.cjs} +2 -2
  8. package/dist/{generators-CYoqgYAV.cjs.map → generators-C6VGGGTj.cjs.map} +1 -1
  9. package/dist/{generators-cZao868O.js → generators-DzaRYGiz.js} +2 -2
  10. package/dist/{generators-cZao868O.js.map → generators-DzaRYGiz.js.map} +1 -1
  11. package/dist/generators.cjs +1 -1
  12. package/dist/generators.js +1 -1
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.js +2 -2
  15. package/package.json +10 -10
  16. package/src/components/InfiniteQuery.tsx +35 -30
  17. package/src/components/InfiniteQueryOptions.tsx +38 -27
  18. package/src/components/Mutation.tsx +3 -1
  19. package/src/components/Query.tsx +31 -23
  20. package/src/components/QueryKey.tsx +8 -6
  21. package/src/components/QueryOptions.tsx +48 -26
  22. package/src/components/SuspenseInfiniteQuery.tsx +31 -26
  23. package/src/components/SuspenseInfiniteQueryOptions.tsx +38 -27
  24. package/src/components/SuspenseQuery.tsx +35 -24
  25. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
  26. package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
  27. package/src/generators/__snapshots__/findByStatusAllOptional.ts +82 -0
  28. package/src/generators/__snapshots__/findByStatusAllOptionalInline.ts +76 -0
  29. package/src/generators/__snapshots__/findByTags.ts +1 -1
  30. package/src/generators/__snapshots__/findByTagsObject.ts +1 -1
  31. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
  32. package/src/generators/__snapshots__/findByTagsTemplateString.ts +1 -1
  33. package/src/generators/__snapshots__/findByTagsWithCustomOptions.ts +1 -1
  34. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +1 -1
  35. package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
  36. package/src/generators/__snapshots__/findInfiniteByStatusAllOptional.ts +97 -0
  37. package/src/generators/__snapshots__/findInfiniteByTags.ts +1 -1
  38. package/src/generators/__snapshots__/findInfiniteByTagsNextAndPreviousParam.ts +1 -1
  39. package/src/generators/__snapshots__/findInfiniteByTagsNextParam.ts +1 -1
  40. package/src/generators/__snapshots__/findInfiniteByTagsWithCustomOptions.ts +1 -1
  41. package/src/generators/__snapshots__/findSuspenseByStatusAllOptional.ts +79 -0
  42. package/src/generators/__snapshots__/findSuspenseByTags.ts +1 -1
  43. package/src/generators/__snapshots__/findSuspenseByTagsWithCustomOptions.ts +1 -1
  44. package/src/generators/__snapshots__/findSuspenseInfiniteByStatusAllOptional.ts +97 -0
  45. package/src/generators/__snapshots__/findSuspenseInfiniteByTags.ts +2 -1
  46. package/src/generators/__snapshots__/findSuspenseInfiniteByTagsCursor.ts +2 -1
  47. package/src/generators/__snapshots__/findSuspenseInfiniteByTagsWithCustomOptions.ts +2 -1
  48. package/src/generators/__snapshots__/postAsQuery.ts +2 -2
  49. package/dist/components-6nRaAppd.cjs.map +0 -1
  50. package/dist/components-B6lqcqgn.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { getNestedAccessor } from '@kubb/core/utils'
2
- import { isOptional } from '@kubb/oas'
2
+ import { isAllOptional, isOptional } from '@kubb/oas'
3
3
  import { Client } from '@kubb/plugin-client/components'
4
4
  import type { OperationSchemas } from '@kubb/plugin-oas'
5
5
  import { getPathParams } from '@kubb/plugin-oas/utils'
@@ -33,33 +33,38 @@ type GetParamsProps = {
33
33
 
34
34
  function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
35
35
  if (paramsType === 'object') {
36
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
37
+
38
+ const children = {
39
+ ...pathParams,
40
+ data: typeSchemas.request?.name
41
+ ? {
42
+ type: typeSchemas.request?.name,
43
+ optional: isOptional(typeSchemas.request?.schema),
44
+ }
45
+ : undefined,
46
+ params: typeSchemas.queryParams?.name
47
+ ? {
48
+ type: typeSchemas.queryParams?.name,
49
+ optional: isOptional(typeSchemas.queryParams?.schema),
50
+ }
51
+ : undefined,
52
+ headers: typeSchemas.headerParams?.name
53
+ ? {
54
+ type: typeSchemas.headerParams?.name,
55
+ optional: isOptional(typeSchemas.headerParams?.schema),
56
+ }
57
+ : undefined,
58
+ }
59
+
60
+ // Check if all children are optional or undefined
61
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
62
+
36
63
  return FunctionParams.factory({
37
64
  data: {
38
65
  mode: 'object',
39
- children: {
40
- ...getPathParams(typeSchemas.pathParams, {
41
- typed: true,
42
- casing: paramsCasing,
43
- }),
44
- data: typeSchemas.request?.name
45
- ? {
46
- type: typeSchemas.request?.name,
47
- optional: isOptional(typeSchemas.request?.schema),
48
- }
49
- : undefined,
50
- params: typeSchemas.queryParams?.name
51
- ? {
52
- type: typeSchemas.queryParams?.name,
53
- optional: isOptional(typeSchemas.queryParams?.schema),
54
- }
55
- : undefined,
56
- headers: typeSchemas.headerParams?.name
57
- ? {
58
- type: typeSchemas.headerParams?.name,
59
- optional: isOptional(typeSchemas.headerParams?.schema),
60
- }
61
- : undefined,
62
- },
66
+ children,
67
+ default: allChildrenAreOptional ? '{}' : undefined,
63
68
  },
64
69
  config: {
65
70
  type: typeSchemas.request?.name
@@ -78,7 +83,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge
78
83
  typed: true,
79
84
  casing: paramsCasing,
80
85
  }),
81
- optional: isOptional(typeSchemas.pathParams?.schema),
86
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
82
87
  }
83
88
  : undefined,
84
89
  data: typeSchemas.request?.name
@@ -212,8 +217,14 @@ export function InfiniteQueryOptions({
212
217
  } as ${typeSchemas.queryParams?.name}`
213
218
  : ''
214
219
 
220
+ // Only add enabled check for required (non-optional) parameters
221
+ // Optional parameters with defaults should not prevent query execution
215
222
  const enabled = Object.entries(queryKeyParams.flatParams)
216
- .map(([key, item]) => (item && !item.optional ? key : undefined))
223
+ .map(([key, item]) => {
224
+ // Only include if the parameter exists and is NOT optional
225
+ // This ensures we only check required parameters
226
+ return item && !item.optional && !item.default ? key : undefined
227
+ })
217
228
  .filter(Boolean)
218
229
  .join('&& ')
219
230
 
@@ -32,8 +32,10 @@ type GetParamsProps = {
32
32
 
33
33
  function getParams({ paramsCasing, dataReturnType, typeSchemas }: GetParamsProps) {
34
34
  const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
35
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
36
+
35
37
  const mutationParams = FunctionParams.factory({
36
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
38
+ ...pathParams,
37
39
  data: typeSchemas.request?.name
38
40
  ? {
39
41
  type: typeSchemas.request?.name,
@@ -1,4 +1,4 @@
1
- import { isOptional, type Operation } from '@kubb/oas'
1
+ import { isAllOptional, isOptional, type Operation } from '@kubb/oas'
2
2
  import type { OperationSchemas } from '@kubb/plugin-oas'
3
3
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
4
4
  import { File, Function, FunctionParams } from '@kubb/react-fabric'
@@ -37,30 +37,38 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t
37
37
  const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
38
38
 
39
39
  if (paramsType === 'object') {
40
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
41
+
42
+ const children = {
43
+ ...pathParams,
44
+ data: typeSchemas.request?.name
45
+ ? {
46
+ type: typeSchemas.request?.name,
47
+ optional: isOptional(typeSchemas.request?.schema),
48
+ }
49
+ : undefined,
50
+ params: typeSchemas.queryParams?.name
51
+ ? {
52
+ type: typeSchemas.queryParams?.name,
53
+ optional: isOptional(typeSchemas.queryParams?.schema),
54
+ }
55
+ : undefined,
56
+ headers: typeSchemas.headerParams?.name
57
+ ? {
58
+ type: typeSchemas.headerParams?.name,
59
+ optional: isOptional(typeSchemas.headerParams?.schema),
60
+ }
61
+ : undefined,
62
+ }
63
+
64
+ // Check if all children are optional or undefined
65
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
66
+
40
67
  return FunctionParams.factory({
41
68
  data: {
42
69
  mode: 'object',
43
- children: {
44
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
45
- data: typeSchemas.request?.name
46
- ? {
47
- type: typeSchemas.request?.name,
48
- optional: isOptional(typeSchemas.request?.schema),
49
- }
50
- : undefined,
51
- params: typeSchemas.queryParams?.name
52
- ? {
53
- type: typeSchemas.queryParams?.name,
54
- optional: isOptional(typeSchemas.queryParams?.schema),
55
- }
56
- : undefined,
57
- headers: typeSchemas.headerParams?.name
58
- ? {
59
- type: typeSchemas.headerParams?.name,
60
- optional: isOptional(typeSchemas.headerParams?.schema),
61
- }
62
- : undefined,
63
- },
70
+ children,
71
+ default: allChildrenAreOptional ? '{}' : undefined,
64
72
  },
65
73
  options: {
66
74
  type: `
@@ -79,7 +87,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t
79
87
  ? {
80
88
  mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
81
89
  children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
82
- optional: isOptional(typeSchemas.pathParams?.schema),
90
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
83
91
  }
84
92
  : undefined,
85
93
  data: typeSchemas.request?.name
@@ -24,20 +24,22 @@ type GetParamsProps = {
24
24
 
25
25
  function getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {
26
26
  return FunctionParams.factory({
27
- pathParams: {
28
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
29
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
30
- },
27
+ pathParams: typeSchemas.pathParams?.name
28
+ ? {
29
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
30
+ children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
31
+ }
32
+ : undefined,
31
33
  data: typeSchemas.request?.name
32
34
  ? {
33
35
  type: typeSchemas.request?.name,
34
- optional: isOptional(typeSchemas.request?.schema),
36
+ default: isOptional(typeSchemas.request?.schema) ? '{}' : undefined,
35
37
  }
36
38
  : undefined,
37
39
  params: typeSchemas.queryParams?.name
38
40
  ? {
39
41
  type: typeSchemas.queryParams?.name,
40
- optional: isOptional(typeSchemas.queryParams?.schema),
42
+ default: isOptional(typeSchemas.queryParams?.schema) ? '{}' : undefined,
41
43
  }
42
44
  : undefined,
43
45
  })
@@ -1,4 +1,4 @@
1
- import { isOptional } from '@kubb/oas'
1
+ import { isAllOptional, isOptional } from '@kubb/oas'
2
2
  import { Client } from '@kubb/plugin-client/components'
3
3
  import type { OperationSchemas } from '@kubb/plugin-oas'
4
4
  import { getPathParams } from '@kubb/plugin-oas/utils'
@@ -27,30 +27,38 @@ type GetParamsProps = {
27
27
 
28
28
  function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
29
29
  if (paramsType === 'object') {
30
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
31
+
32
+ const children = {
33
+ ...pathParams,
34
+ data: typeSchemas.request?.name
35
+ ? {
36
+ type: typeSchemas.request?.name,
37
+ optional: isOptional(typeSchemas.request?.schema),
38
+ }
39
+ : undefined,
40
+ params: typeSchemas.queryParams?.name
41
+ ? {
42
+ type: typeSchemas.queryParams?.name,
43
+ optional: isOptional(typeSchemas.queryParams?.schema),
44
+ }
45
+ : undefined,
46
+ headers: typeSchemas.headerParams?.name
47
+ ? {
48
+ type: typeSchemas.headerParams?.name,
49
+ optional: isOptional(typeSchemas.headerParams?.schema),
50
+ }
51
+ : undefined,
52
+ }
53
+
54
+ // Check if all children are optional or undefined
55
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
56
+
30
57
  return FunctionParams.factory({
31
58
  data: {
32
59
  mode: 'object',
33
- children: {
34
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
35
- data: typeSchemas.request?.name
36
- ? {
37
- type: typeSchemas.request?.name,
38
- optional: isOptional(typeSchemas.request?.schema),
39
- }
40
- : undefined,
41
- params: typeSchemas.queryParams?.name
42
- ? {
43
- type: typeSchemas.queryParams?.name,
44
- optional: isOptional(typeSchemas.queryParams?.schema),
45
- }
46
- : undefined,
47
- headers: typeSchemas.headerParams?.name
48
- ? {
49
- type: typeSchemas.headerParams?.name,
50
- optional: isOptional(typeSchemas.headerParams?.schema),
51
- }
52
- : undefined,
53
- },
60
+ children,
61
+ default: allChildrenAreOptional ? '{}' : undefined,
54
62
  },
55
63
  config: {
56
64
  type: typeSchemas.request?.name
@@ -65,8 +73,11 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge
65
73
  pathParams: typeSchemas.pathParams?.name
66
74
  ? {
67
75
  mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
68
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
69
- optional: isOptional(typeSchemas.pathParams?.schema),
76
+ children: getPathParams(typeSchemas.pathParams, {
77
+ typed: true,
78
+ casing: paramsCasing,
79
+ }),
80
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
70
81
  }
71
82
  : undefined,
72
83
  data: typeSchemas.request?.name
@@ -97,7 +108,12 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge
97
108
  }
98
109
 
99
110
  export function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }: Props): KubbNode {
100
- const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
111
+ const params = getParams({
112
+ paramsType,
113
+ paramsCasing,
114
+ pathParamsType,
115
+ typeSchemas,
116
+ })
101
117
  const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
102
118
  const TError = typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'
103
119
 
@@ -114,8 +130,14 @@ export function QueryOptions({ name, clientName, dataReturnType, typeSchemas, pa
114
130
  paramsCasing,
115
131
  })
116
132
 
133
+ // Only add enabled check for required (non-optional) parameters
134
+ // Optional parameters with defaults should not prevent query execution
117
135
  const enabled = Object.entries(queryKeyParams.flatParams)
118
- .map(([key, item]) => (item && !item.optional ? key : undefined))
136
+ .map(([key, item]) => {
137
+ // Only include if the parameter exists and is NOT optional
138
+ // This ensures we only check required parameters
139
+ return item && !item.optional && !item.default ? key : undefined
140
+ })
119
141
  .filter(Boolean)
120
142
  .join('&& ')
121
143
 
@@ -1,4 +1,4 @@
1
- import { isOptional, type Operation } from '@kubb/oas'
1
+ import { isAllOptional, isOptional, type Operation } from '@kubb/oas'
2
2
  import type { OperationSchemas } from '@kubb/plugin-oas'
3
3
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
4
4
  import { File, Function, FunctionParams } from '@kubb/react-fabric'
@@ -36,33 +36,38 @@ type GetParamsProps = {
36
36
 
37
37
  function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }: GetParamsProps) {
38
38
  if (paramsType === 'object') {
39
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
40
+
41
+ const children = {
42
+ ...pathParams,
43
+ data: typeSchemas.request?.name
44
+ ? {
45
+ type: typeSchemas.request?.name,
46
+ optional: isOptional(typeSchemas.request?.schema),
47
+ }
48
+ : undefined,
49
+ params: typeSchemas.queryParams?.name
50
+ ? {
51
+ type: typeSchemas.queryParams?.name,
52
+ optional: isOptional(typeSchemas.queryParams?.schema),
53
+ }
54
+ : undefined,
55
+ headers: typeSchemas.headerParams?.name
56
+ ? {
57
+ type: typeSchemas.headerParams?.name,
58
+ optional: isOptional(typeSchemas.headerParams?.schema),
59
+ }
60
+ : undefined,
61
+ }
62
+
63
+ // Check if all children are optional or undefined
64
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
65
+
39
66
  return FunctionParams.factory({
40
67
  data: {
41
68
  mode: 'object',
42
- children: {
43
- ...getPathParams(typeSchemas.pathParams, {
44
- typed: true,
45
- casing: paramsCasing,
46
- }),
47
- data: typeSchemas.request?.name
48
- ? {
49
- type: typeSchemas.request?.name,
50
- optional: isOptional(typeSchemas.request?.schema),
51
- }
52
- : undefined,
53
- params: typeSchemas.queryParams?.name
54
- ? {
55
- type: typeSchemas.queryParams?.name,
56
- optional: isOptional(typeSchemas.queryParams?.schema),
57
- }
58
- : undefined,
59
- headers: typeSchemas.headerParams?.name
60
- ? {
61
- type: typeSchemas.headerParams?.name,
62
- optional: isOptional(typeSchemas.headerParams?.schema),
63
- }
64
- : undefined,
65
- },
69
+ children,
70
+ default: allChildrenAreOptional ? '{}' : undefined,
66
71
  },
67
72
  options: {
68
73
  type: `
@@ -84,7 +89,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, page
84
89
  typed: true,
85
90
  casing: paramsCasing,
86
91
  }),
87
- optional: isOptional(typeSchemas.pathParams?.schema),
92
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
88
93
  }
89
94
  : undefined,
90
95
  data: typeSchemas.request?.name
@@ -1,5 +1,5 @@
1
1
  import { getNestedAccessor } from '@kubb/core/utils'
2
- import { isOptional } from '@kubb/oas'
2
+ import { isAllOptional, isOptional } from '@kubb/oas'
3
3
  import { Client } from '@kubb/plugin-client/components'
4
4
  import type { OperationSchemas } from '@kubb/plugin-oas'
5
5
  import { getPathParams } from '@kubb/plugin-oas/utils'
@@ -33,33 +33,38 @@ type GetParamsProps = {
33
33
 
34
34
  function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
35
35
  if (paramsType === 'object') {
36
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
37
+
38
+ const children = {
39
+ ...pathParams,
40
+ data: typeSchemas.request?.name
41
+ ? {
42
+ type: typeSchemas.request?.name,
43
+ optional: isOptional(typeSchemas.request?.schema),
44
+ }
45
+ : undefined,
46
+ params: typeSchemas.queryParams?.name
47
+ ? {
48
+ type: typeSchemas.queryParams?.name,
49
+ optional: isOptional(typeSchemas.queryParams?.schema),
50
+ }
51
+ : undefined,
52
+ headers: typeSchemas.headerParams?.name
53
+ ? {
54
+ type: typeSchemas.headerParams?.name,
55
+ optional: isOptional(typeSchemas.headerParams?.schema),
56
+ }
57
+ : undefined,
58
+ }
59
+
60
+ // Check if all children are optional or undefined
61
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
62
+
36
63
  return FunctionParams.factory({
37
64
  data: {
38
65
  mode: 'object',
39
- children: {
40
- ...getPathParams(typeSchemas.pathParams, {
41
- typed: true,
42
- casing: paramsCasing,
43
- }),
44
- data: typeSchemas.request?.name
45
- ? {
46
- type: typeSchemas.request?.name,
47
- optional: isOptional(typeSchemas.request?.schema),
48
- }
49
- : undefined,
50
- params: typeSchemas.queryParams?.name
51
- ? {
52
- type: typeSchemas.queryParams?.name,
53
- optional: isOptional(typeSchemas.queryParams?.schema),
54
- }
55
- : undefined,
56
- headers: typeSchemas.headerParams?.name
57
- ? {
58
- type: typeSchemas.headerParams?.name,
59
- optional: isOptional(typeSchemas.headerParams?.schema),
60
- }
61
- : undefined,
62
- },
66
+ children,
67
+ default: allChildrenAreOptional ? '{}' : undefined,
63
68
  },
64
69
  config: {
65
70
  type: typeSchemas.request?.name
@@ -78,7 +83,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge
78
83
  typed: true,
79
84
  casing: paramsCasing,
80
85
  }),
81
- optional: isOptional(typeSchemas.pathParams?.schema),
86
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
82
87
  }
83
88
  : undefined,
84
89
  data: typeSchemas.request?.name
@@ -212,8 +217,14 @@ export function SuspenseInfiniteQueryOptions({
212
217
  } as ${typeSchemas.queryParams?.name}`
213
218
  : ''
214
219
 
220
+ // Only add enabled check for required (non-optional) parameters
221
+ // Optional parameters with defaults should not prevent query execution
215
222
  const enabled = Object.entries(queryKeyParams.flatParams)
216
- .map(([key, item]) => (item && !item.optional ? key : undefined))
223
+ .map(([key, item]) => {
224
+ // Only include if the parameter exists and is NOT optional
225
+ // This ensures we only check required parameters
226
+ return item && !item.optional && !item.default ? key : undefined
227
+ })
217
228
  .filter(Boolean)
218
229
  .join('&& ')
219
230
 
@@ -1,4 +1,4 @@
1
- import { isOptional, type Operation } from '@kubb/oas'
1
+ import { isAllOptional, isOptional, type Operation } from '@kubb/oas'
2
2
  import type { OperationSchemas } from '@kubb/plugin-oas'
3
3
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
4
4
  import { File, Function, FunctionParams } from '@kubb/react-fabric'
@@ -37,30 +37,38 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t
37
37
  const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
38
38
 
39
39
  if (paramsType === 'object') {
40
+ const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
41
+
42
+ const children = {
43
+ ...pathParams,
44
+ data: typeSchemas.request?.name
45
+ ? {
46
+ type: typeSchemas.request?.name,
47
+ optional: isOptional(typeSchemas.request?.schema),
48
+ }
49
+ : undefined,
50
+ params: typeSchemas.queryParams?.name
51
+ ? {
52
+ type: typeSchemas.queryParams?.name,
53
+ optional: isOptional(typeSchemas.queryParams?.schema),
54
+ }
55
+ : undefined,
56
+ headers: typeSchemas.headerParams?.name
57
+ ? {
58
+ type: typeSchemas.headerParams?.name,
59
+ optional: isOptional(typeSchemas.headerParams?.schema),
60
+ }
61
+ : undefined,
62
+ }
63
+
64
+ // Check if all children are optional or undefined
65
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
66
+
40
67
  return FunctionParams.factory({
41
68
  data: {
42
69
  mode: 'object',
43
- children: {
44
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
45
- data: typeSchemas.request?.name
46
- ? {
47
- type: typeSchemas.request?.name,
48
- optional: isOptional(typeSchemas.request?.schema),
49
- }
50
- : undefined,
51
- params: typeSchemas.queryParams?.name
52
- ? {
53
- type: typeSchemas.queryParams?.name,
54
- optional: isOptional(typeSchemas.queryParams?.schema),
55
- }
56
- : undefined,
57
- headers: typeSchemas.headerParams?.name
58
- ? {
59
- type: typeSchemas.headerParams?.name,
60
- optional: isOptional(typeSchemas.headerParams?.schema),
61
- }
62
- : undefined,
63
- },
70
+ children,
71
+ default: allChildrenAreOptional ? '{}' : undefined,
64
72
  },
65
73
  options: {
66
74
  type: `
@@ -78,8 +86,11 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t
78
86
  pathParams: typeSchemas.pathParams?.name
79
87
  ? {
80
88
  mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
81
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
82
- optional: isOptional(typeSchemas.pathParams?.schema),
89
+ children: getPathParams(typeSchemas.pathParams, {
90
+ typed: true,
91
+ casing: paramsCasing,
92
+ }),
93
+ default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
83
94
  }
84
95
  : undefined,
85
96
  data: typeSchemas.request?.name
@@ -7,7 +7,7 @@ import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryResult } from
7
7
  import { fetch } from './test/.kubb/fetch'
8
8
  import { queryOptions, useQuery } from '@tanstack/react-query'
9
9
 
10
- export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
10
+ export const findPetsByTagsQueryKey = (params: FindPetsByTagsQueryParams = {}) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
12
12
  export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>
13
13
 
@@ -7,7 +7,7 @@ import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryResult } from
7
7
  import type { RequestConfig, ResponseErrorConfig } from 'axios'
8
8
  import { queryOptions, useQuery } from '@tanstack/react-query'
9
9
 
10
- export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
10
+ export const findPetsByTagsQueryKey = (params: FindPetsByTagsQueryParams = {}) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
12
12
  export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>
13
13
 
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Generated by Kubb (https://kubb.dev/).
3
+ * Do not edit manually.
4
+ */
5
+ import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
6
+ import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryResult } from '@tanstack/react-query'
7
+ import { fetch } from './test/.kubb/fetch'
8
+ import { queryOptions, useQuery } from '@tanstack/react-query'
9
+
10
+ export const findPetsByStatusQueryKey = (params: FindPetsByStatusQueryParams = {}) => [{ url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const
11
+
12
+ export type FindPetsByStatusQueryKey = ReturnType<typeof findPetsByStatusQueryKey>
13
+
14
+ /**
15
+ * @description Multiple status values can be provided with comma separated strings
16
+ * @summary Finds Pets by status
17
+ * {@link /pet/findByStatus}
18
+ */
19
+ export async function findPetsByStatus(
20
+ { params }: { params?: FindPetsByStatusQueryParams } = {},
21
+ config: Partial<RequestConfig> & { client?: typeof fetch } = {},
22
+ ) {
23
+ const { client: request = fetch, ...requestConfig } = config
24
+
25
+ const res = await request<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, unknown>({
26
+ method: 'GET',
27
+ url: `/pet/findByStatus`,
28
+ params,
29
+ ...requestConfig,
30
+ })
31
+ return findPetsByStatusQueryResponse.parse(res.data)
32
+ }
33
+
34
+ export function findPetsByStatusQueryOptions(
35
+ { params }: { params?: FindPetsByStatusQueryParams } = {},
36
+ config: Partial<RequestConfig> & { client?: typeof fetch } = {},
37
+ ) {
38
+ const queryKey = findPetsByStatusQueryKey(params)
39
+ return queryOptions<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, FindPetsByStatusQueryResponse, typeof queryKey>({
40
+ queryKey,
41
+ queryFn: async ({ signal }) => {
42
+ config.signal = signal
43
+ return findPetsByStatus({ params }, config)
44
+ },
45
+ })
46
+ }
47
+
48
+ /**
49
+ * @description Multiple status values can be provided with comma separated strings
50
+ * @summary Finds Pets by status
51
+ * {@link /pet/findByStatus}
52
+ */
53
+ export function useFindPetsByStatus<
54
+ TData = FindPetsByStatusQueryResponse,
55
+ TQueryData = FindPetsByStatusQueryResponse,
56
+ TQueryKey extends QueryKey = FindPetsByStatusQueryKey,
57
+ >(
58
+ { params }: { params?: FindPetsByStatusQueryParams } = {},
59
+ options: {
60
+ query?: Partial<QueryObserverOptions<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, TData, TQueryData, TQueryKey>> & {
61
+ client?: QueryClient
62
+ }
63
+ client?: Partial<RequestConfig> & { client?: typeof fetch }
64
+ } = {},
65
+ ) {
66
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
67
+ const { client: queryClient, ...queryOptions } = queryConfig
68
+ const queryKey = queryOptions?.queryKey ?? findPetsByStatusQueryKey(params)
69
+
70
+ const query = useQuery(
71
+ {
72
+ ...findPetsByStatusQueryOptions({ params }, config),
73
+ queryKey,
74
+ ...queryOptions,
75
+ } as unknown as QueryObserverOptions,
76
+ queryClient,
77
+ ) as UseQueryResult<TData, ResponseErrorConfig<FindPetsByStatus400>> & { queryKey: TQueryKey }
78
+
79
+ query.queryKey = queryKey as TQueryKey
80
+
81
+ return query
82
+ }