react-query-lightbase-codegen 2.0.9 → 2.1.1
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/generator/clientGenerator.js +6 -2
- package/dist/generator/reactQueryGenerator.js +5 -4
- package/dist/generator/schemaGenerator.js +3 -0
- package/package.json +1 -1
- package/src/generator/clientGenerator.ts +7 -2
- package/src/generator/instanceGenerator.ts +0 -2
- package/src/generator/reactQueryGenerator.ts +5 -4
- package/src/generator/schemaGenerator.ts +3 -0
|
@@ -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,15 +121,18 @@ 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
|
]
|
|
127
128
|
.filter(Boolean)
|
|
128
129
|
.join("\n ");
|
|
130
|
+
const requestParms = hasData
|
|
131
|
+
? `props: ${dataType} & { axiosConfig?: AxiosRequestConfig; }`
|
|
132
|
+
: "props?: { axiosConfig?: AxiosRequestConfig }";
|
|
129
133
|
return `
|
|
130
134
|
${jsDocLines.join("\n ")}
|
|
131
|
-
export async function ${(0, utils_1.camelCase)(operationId)}(
|
|
135
|
+
export async function ${(0, utils_1.camelCase)(operationId)}(${requestParms}): Promise<${responseType}> {
|
|
132
136
|
${methodBody}
|
|
133
137
|
}`;
|
|
134
138
|
}
|
|
@@ -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
|
}
|
|
@@ -18,6 +18,9 @@ function getTypeFromSchema(schema, context) {
|
|
|
18
18
|
}
|
|
19
19
|
switch (schema.type) {
|
|
20
20
|
case "string":
|
|
21
|
+
if ("format" in schema && schema.format === "binary") {
|
|
22
|
+
return "string | { name?: string; type?: string; uri: string }";
|
|
23
|
+
}
|
|
21
24
|
return "string";
|
|
22
25
|
case "number":
|
|
23
26
|
case "integer":
|
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,16 +147,20 @@ 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
|
]
|
|
153
154
|
.filter(Boolean)
|
|
154
155
|
.join("\n ");
|
|
155
156
|
|
|
157
|
+
const requestParms = hasData
|
|
158
|
+
? `props: ${dataType} & { axiosConfig?: AxiosRequestConfig; }`
|
|
159
|
+
: "props?: { axiosConfig?: AxiosRequestConfig }";
|
|
160
|
+
|
|
156
161
|
return `
|
|
157
162
|
${jsDocLines.join("\n ")}
|
|
158
|
-
export async function ${camelCase(operationId)}(
|
|
163
|
+
export async function ${camelCase(operationId)}(${requestParms}): Promise<${responseType}> {
|
|
159
164
|
${methodBody}
|
|
160
165
|
}`;
|
|
161
166
|
}
|
|
@@ -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
|
}
|
|
@@ -27,6 +27,9 @@ function getTypeFromSchema(
|
|
|
27
27
|
|
|
28
28
|
switch (schema.type) {
|
|
29
29
|
case "string":
|
|
30
|
+
if ("format" in schema && schema.format === "binary") {
|
|
31
|
+
return "string | { name?: string; type?: string; uri: string }";
|
|
32
|
+
}
|
|
30
33
|
return "string";
|
|
31
34
|
case "number":
|
|
32
35
|
case "integer":
|