react-query-lightbase-codegen 2.5.2 → 2.5.4
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.
|
@@ -69,15 +69,14 @@ function generateAxiosMethod(operation, spec) {
|
|
|
69
69
|
const responseType = responseDetails?.[0] && "content" in responseDetails[1]
|
|
70
70
|
? `T.${`${namedType}Response${responseDetails[0]}`}`
|
|
71
71
|
: "unknown";
|
|
72
|
-
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "
|
|
72
|
+
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "encodeURIComponent(data.$1)")}\`` : `"${path}"`;
|
|
73
73
|
const methodBody = [
|
|
74
74
|
`${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
|
|
75
75
|
"const apiClient = getApiClient();",
|
|
76
76
|
`const url = ${urlWithParams};`,
|
|
77
77
|
queryParams.length > 0
|
|
78
|
-
? `const queryData =
|
|
79
|
-
${queryParams.map((p) => `
|
|
80
|
-
};`
|
|
78
|
+
? `const queryData = new URLSearchParams();
|
|
79
|
+
${queryParams.map((p) => `queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));`).join("\n ")}`
|
|
81
80
|
: "",
|
|
82
81
|
requestBodySchema?.properties
|
|
83
82
|
? `const bodyData = {
|
|
@@ -100,7 +99,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
100
99
|
})
|
|
101
100
|
.join("\n ")}`
|
|
102
101
|
: "",
|
|
103
|
-
queryParams.length > 0 ? "axiosConfig.params = queryData;" : "",
|
|
102
|
+
queryParams.length > 0 ? "axiosConfig.params = { ...axiosConfig.params, ...queryData };" : "",
|
|
104
103
|
isFormData
|
|
105
104
|
? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
|
|
106
105
|
: "",
|
package/package.json
CHANGED
|
@@ -100,16 +100,16 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
100
100
|
? `T.${`${namedType}Response${responseDetails[0]}`}`
|
|
101
101
|
: "unknown";
|
|
102
102
|
|
|
103
|
-
const urlWithParams =
|
|
103
|
+
const urlWithParams =
|
|
104
|
+
urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "encodeURIComponent(data.$1)")}\`` : `"${path}"`;
|
|
104
105
|
|
|
105
106
|
const methodBody = [
|
|
106
107
|
`${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
|
|
107
108
|
"const apiClient = getApiClient();",
|
|
108
109
|
`const url = ${urlWithParams};`,
|
|
109
110
|
queryParams.length > 0
|
|
110
|
-
? `const queryData =
|
|
111
|
-
${queryParams.map((p) => `
|
|
112
|
-
};`
|
|
111
|
+
? `const queryData = new URLSearchParams();
|
|
112
|
+
${queryParams.map((p) => `queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));`).join("\n ")}`
|
|
113
113
|
: "",
|
|
114
114
|
requestBodySchema?.properties
|
|
115
115
|
? `const bodyData = {
|
|
@@ -132,7 +132,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
132
132
|
})
|
|
133
133
|
.join("\n ")}`
|
|
134
134
|
: "",
|
|
135
|
-
queryParams.length > 0 ? "axiosConfig.params = queryData;" : "",
|
|
135
|
+
queryParams.length > 0 ? "axiosConfig.params = { ...axiosConfig.params, ...queryData };" : "",
|
|
136
136
|
isFormData
|
|
137
137
|
? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
|
|
138
138
|
: "",
|