@kubb/plugin-react-query 4.15.0 → 4.15.2
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.
- package/dist/{components-CX83mklO.js → components-DVc9iach.js} +261 -218
- package/dist/components-DVc9iach.js.map +1 -0
- package/dist/{components-7ul5AP_u.cjs → components-YtTYHVwV.cjs} +261 -218
- package/dist/components-YtTYHVwV.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-CNv1RI1y.cjs → generators-C6VGGGTj.cjs} +2 -2
- package/dist/{generators-CNv1RI1y.cjs.map → generators-C6VGGGTj.cjs.map} +1 -1
- package/dist/{generators-CVc1Qlnh.js → generators-DzaRYGiz.js} +2 -2
- package/dist/{generators-CVc1Qlnh.js.map → generators-DzaRYGiz.js.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/package.json +9 -9
- package/src/components/InfiniteQuery.tsx +35 -30
- package/src/components/InfiniteQueryOptions.tsx +38 -27
- package/src/components/Mutation.tsx +3 -1
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +31 -23
- package/src/components/QueryKey.tsx +8 -6
- package/src/components/QueryOptions.tsx +48 -26
- package/src/components/SuspenseInfiniteQuery.tsx +31 -26
- package/src/components/SuspenseInfiniteQueryOptions.tsx +38 -27
- package/src/components/SuspenseQuery.tsx +35 -24
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/clientPostImportPath.ts +4 -2
- package/src/generators/__snapshots__/findByStatusAllOptional.ts +82 -0
- package/src/generators/__snapshots__/findByStatusAllOptionalInline.ts +76 -0
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsTemplateString.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomOptions.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByStatusAllOptional.ts +97 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsNextAndPreviousParam.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsNextParam.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsWithCustomOptions.ts +1 -1
- package/src/generators/__snapshots__/findSuspenseByStatusAllOptional.ts +79 -0
- package/src/generators/__snapshots__/findSuspenseByTags.ts +1 -1
- package/src/generators/__snapshots__/findSuspenseByTagsWithCustomOptions.ts +1 -1
- package/src/generators/__snapshots__/findSuspenseInfiniteByStatusAllOptional.ts +97 -0
- package/src/generators/__snapshots__/findSuspenseInfiniteByTags.ts +2 -1
- package/src/generators/__snapshots__/findSuspenseInfiniteByTagsCursor.ts +2 -1
- package/src/generators/__snapshots__/findSuspenseInfiniteByTagsWithCustomOptions.ts +2 -1
- package/src/generators/__snapshots__/postAsQuery.ts +2 -2
- package/src/generators/__snapshots__/updatePetById.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdWithCustomOptions.ts +4 -2
- package/dist/components-7ul5AP_u.cjs.map +0 -1
- package/dist/components-CX83mklO.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
|
-
|
|
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
|
-
|
|
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]) =>
|
|
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
|
-
...
|
|
38
|
+
...pathParams,
|
|
37
39
|
data: typeSchemas.request?.name
|
|
38
40
|
? {
|
|
39
41
|
type: typeSchemas.request?.name,
|
|
@@ -95,10 +95,10 @@ export function MutationOptions({ name, clientName, dataReturnType, typeSchemas,
|
|
|
95
95
|
|
|
96
96
|
return (
|
|
97
97
|
<File.Source name={name} isExportable isIndexable>
|
|
98
|
-
<Function name={name} export params={params.toConstructor()}>
|
|
98
|
+
<Function name={name} export params={params.toConstructor()} generics={['TContext = unknown']}>
|
|
99
99
|
{`
|
|
100
100
|
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
101
|
-
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : 'void'},
|
|
101
|
+
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : 'void'}, TContext>({
|
|
102
102
|
mutationKey,
|
|
103
103
|
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
104
104
|
return ${clientName}(${clientParams.toCall()})
|
package/src/components/Query.tsx
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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, {
|
|
69
|
-
|
|
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({
|
|
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]) =>
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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]) =>
|
|
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
|
-
|
|
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, {
|
|
82
|
-
|
|
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
|
|
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
|
|
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
|
|
|
@@ -35,13 +35,15 @@ export async function updatePetWithForm(
|
|
|
35
35
|
return updatePetWithFormMutationResponse.parse(res.data)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function updatePetWithFormMutationOptions
|
|
38
|
+
export function updatePetWithFormMutationOptions<TContext = unknown>(
|
|
39
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
40
|
+
) {
|
|
39
41
|
const mutationKey = updatePetWithFormMutationKey()
|
|
40
42
|
return mutationOptions<
|
|
41
43
|
UpdatePetWithFormMutationResponse,
|
|
42
44
|
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
43
45
|
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
44
|
-
|
|
46
|
+
TContext
|
|
45
47
|
>({
|
|
46
48
|
mutationKey,
|
|
47
49
|
mutationFn: async ({ petId, data, params }) => {
|