react-query-lightbase-codegen 2.0.9 → 2.1.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.
|
@@ -89,6 +89,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
89
89
|
const responseType = successResponse ? `T.${`${namedType}Response${successResponse[0]}`}` : "any";
|
|
90
90
|
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${data.$1}")}\`` : `"${path}"`;
|
|
91
91
|
const methodBody = [
|
|
92
|
+
`${hasData ? "const { axiosConfig, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
|
|
92
93
|
"const apiClient = getApiClient();",
|
|
93
94
|
`const url = ${urlWithParams};`,
|
|
94
95
|
queryParams.length > 0
|
|
@@ -120,7 +121,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
120
121
|
`const res = await apiClient.${method}<${responseType}>(url, {
|
|
121
122
|
${queryParams.length > 0 ? "params: queryData," : ""}
|
|
122
123
|
${requestBody ? `data: ${isFormData ? "formData" : "bodyData"},` : ""}
|
|
123
|
-
${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...
|
|
124
|
+
${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig"}
|
|
124
125
|
});
|
|
125
126
|
return res.data;`,
|
|
126
127
|
]
|
|
@@ -128,7 +129,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
128
129
|
.join("\n ");
|
|
129
130
|
return `
|
|
130
131
|
${jsDocLines.join("\n ")}
|
|
131
|
-
export async function ${(0, utils_1.camelCase)(operationId)}(
|
|
132
|
+
export async function ${(0, utils_1.camelCase)(operationId)}(props: ${hasData ? `${dataType} & { axiosConfig?: AxiosRequestConfig; }` : "{ axiosConfig?: AxiosRequestConfig }"} ): Promise<${responseType}> {
|
|
132
133
|
${methodBody}
|
|
133
134
|
}`;
|
|
134
135
|
}
|
|
@@ -31,13 +31,14 @@ function generateQueryOptions(operation, spec) {
|
|
|
31
31
|
const namedQueryOptions = `get${operationId}QueryOptions`;
|
|
32
32
|
const namedQuery = (0, utils_1.camelCase)(`${operationId}`);
|
|
33
33
|
return `
|
|
34
|
-
export const ${namedQueryOptions} = (
|
|
35
|
-
${hasData ? `
|
|
34
|
+
export const ${namedQueryOptions} = (
|
|
35
|
+
${hasData ? `props: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>` : `props?: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>`}
|
|
36
36
|
) => {
|
|
37
|
+
${hasData ? "const { axiosConfig, ...params } = props || {};" : "const { axiosConfig } = props || {};"}
|
|
37
38
|
const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
|
|
38
39
|
return queryOptions({
|
|
39
|
-
queryKey: ['${(0, utils_1.camelCase)(operationId)}', ${hasData ? "params" : "
|
|
40
|
-
queryFn: enabled ? () => apiClient.${namedQuery}(${hasData ? "params" : "
|
|
40
|
+
queryKey: ['${(0, utils_1.camelCase)(operationId)}', ${hasData ? "params" : ""}],
|
|
41
|
+
queryFn: enabled ? () => apiClient.${namedQuery}(${hasData ? "{...params, axiosConfig}" : "{axiosConfig}"}) : skipToken,
|
|
41
42
|
});
|
|
42
43
|
};`;
|
|
43
44
|
}
|
package/package.json
CHANGED
|
@@ -115,6 +115,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
115
115
|
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${data.$1}")}\`` : `"${path}"`;
|
|
116
116
|
|
|
117
117
|
const methodBody = [
|
|
118
|
+
`${hasData ? "const { axiosConfig, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
|
|
118
119
|
"const apiClient = getApiClient();",
|
|
119
120
|
`const url = ${urlWithParams};`,
|
|
120
121
|
queryParams.length > 0
|
|
@@ -146,7 +147,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
146
147
|
`const res = await apiClient.${method}<${responseType}>(url, {
|
|
147
148
|
${queryParams.length > 0 ? "params: queryData," : ""}
|
|
148
149
|
${requestBody ? `data: ${isFormData ? "formData" : "bodyData"},` : ""}
|
|
149
|
-
${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...
|
|
150
|
+
${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig"}
|
|
150
151
|
});
|
|
151
152
|
return res.data;`,
|
|
152
153
|
]
|
|
@@ -155,7 +156,9 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
155
156
|
|
|
156
157
|
return `
|
|
157
158
|
${jsDocLines.join("\n ")}
|
|
158
|
-
export async function ${camelCase(operationId)}(
|
|
159
|
+
export async function ${camelCase(operationId)}(props: ${
|
|
160
|
+
hasData ? `${dataType} & { axiosConfig?: AxiosRequestConfig; }` : "{ axiosConfig?: AxiosRequestConfig }"
|
|
161
|
+
} ): Promise<${responseType}> {
|
|
159
162
|
${methodBody}
|
|
160
163
|
}`;
|
|
161
164
|
}
|
|
@@ -39,13 +39,14 @@ function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document
|
|
|
39
39
|
const namedQuery = camelCase(`${operationId}`);
|
|
40
40
|
|
|
41
41
|
return `
|
|
42
|
-
export const ${namedQueryOptions} = (
|
|
43
|
-
${hasData ? `
|
|
42
|
+
export const ${namedQueryOptions} = (
|
|
43
|
+
${hasData ? `props: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>` : `props?: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>`}
|
|
44
44
|
) => {
|
|
45
|
+
${hasData ? "const { axiosConfig, ...params } = props || {};" : "const { axiosConfig } = props || {};"}
|
|
45
46
|
const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
|
|
46
47
|
return queryOptions({
|
|
47
|
-
queryKey: ['${camelCase(operationId)}', ${hasData ? "params" : "
|
|
48
|
-
queryFn: enabled ? () => apiClient.${namedQuery}(${hasData ? "params" : "
|
|
48
|
+
queryKey: ['${camelCase(operationId)}', ${hasData ? "params" : ""}],
|
|
49
|
+
queryFn: enabled ? () => apiClient.${namedQuery}(${hasData ? "{...params, axiosConfig}" : "{axiosConfig}"}) : skipToken,
|
|
49
50
|
});
|
|
50
51
|
};`;
|
|
51
52
|
}
|