Skip to content

Commit bbfe20c

Browse files
committed
fix: fix incorrect encodeURIComponent handling
1 parent 5dcfa52 commit bbfe20c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/generator/clientGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
101101
: "unknown";
102102

103103
const urlWithParams =
104-
urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "encodeURIComponent(${data.$1})")}\`` : `"${path}"`;
104+
urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${encodeURIComponent(data.$1)}")}\`` : `"${path}"`;
105105

106106
const methodBody = [
107107
`${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
108108
"const apiClient = getApiClient();",
109109
`const url = ${urlWithParams};`,
110110
queryParams.length > 0
111111
? `const queryData = new URLSearchParams();
112-
${queryParams.map((p) => `if (p.name) { queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));}`)}`
112+
${queryParams.map((p) => `if (data["${p.name}"]) { queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));}`)}`
113113
: "",
114114
requestBodySchema?.properties
115115
? `const bodyData = {

0 commit comments

Comments
 (0)