Skip to content

Commit ed07585

Browse files
committed
fix: ensure url query and searchParams are encoded
1 parent 8080ba5 commit ed07585

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/generator/clientGenerator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
100100
? `T.${`${namedType}Response${responseDetails[0]}`}`
101101
: "unknown";
102102

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

105106
const methodBody = [
106107
`${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
107108
"const apiClient = getApiClient();",
108109
`const url = ${urlWithParams};`,
109110
queryParams.length > 0
110-
? `const queryData = {
111-
${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
112-
};`
111+
? `const queryData = new URLSearchParams();
112+
${queryParams.map((p) => `queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));`).join("\n ")}`
113113
: "",
114114
requestBodySchema?.properties
115115
? `const bodyData = {

0 commit comments

Comments
 (0)