react-query-lightbase-codegen 2.5.5 → 2.5.7

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.
@@ -51,6 +51,7 @@ function generateAxiosMethod(operation, spec) {
51
51
  jsDocLines.push(" */");
52
52
  const urlParams = parameters?.filter((p) => p.in === "path") || [];
53
53
  const queryParams = parameters?.filter((p) => p.in === "query") || [];
54
+ const headerParams = parameters?.filter((p) => p.in === "header") || [];
54
55
  const isFormData = requestBody && "content" in requestBody && requestBody.content?.["multipart/form-data"];
55
56
  const formDataSchema = isFormData
56
57
  ? resolveSchema(requestBody.content["multipart/form-data"].schema, spec)
@@ -69,14 +70,15 @@ function generateAxiosMethod(operation, spec) {
69
70
  const responseType = responseDetails?.[0] && "content" in responseDetails[1]
70
71
  ? `T.${`${namedType}Response${responseDetails[0]}`}`
71
72
  : "unknown";
72
- const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "encodeURIComponent(${data.$1})")}\`` : `"${path}"`;
73
+ const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${encodeURIComponent(data.$1)}")}\`` : `"${path}"`;
73
74
  const methodBody = [
74
75
  `${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
75
76
  "const apiClient = getApiClient();",
76
77
  `const url = ${urlWithParams};`,
77
78
  queryParams.length > 0
78
- ? `const queryData = new URLSearchParams();
79
- ${queryParams.map((p) => `if (p.name) { queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));}`)}`
79
+ ? `const queryData = {
80
+ ${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
81
+ };`
80
82
  : "",
81
83
  requestBodySchema?.properties
82
84
  ? `const bodyData = {
@@ -103,6 +105,12 @@ function generateAxiosMethod(operation, spec) {
103
105
  isFormData
104
106
  ? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
105
107
  : "",
108
+ headerParams.length > 0
109
+ ? `const headerData = {
110
+ ${headerParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
111
+ };`
112
+ : "",
113
+ headerParams.length > 0 ? "axiosConfig.headers = { ...axiosConfig.headers, ...headerData };" : "",
106
114
  requestBody
107
115
  ? `const res = await apiClient.${method}<${responseType}>(url, ${formDataSchema?.properties || requestBodySchema?.properties ? "bodyData" : "data"}, axiosConfig);`
108
116
  : `const res = await apiClient.${method}<${responseType}>(url, axiosConfig);`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-lightbase-codegen",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "license": "MIT",
5
5
  "description": "Generate Axios API clients and React Query options from OpenAPI specifications",
6
6
  "exports": "./dist/index.js",
@@ -71,6 +71,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
71
71
 
72
72
  const urlParams = parameters?.filter((p) => p.in === "path") || [];
73
73
  const queryParams = parameters?.filter((p) => p.in === "query") || [];
74
+ const headerParams = parameters?.filter((p) => p.in === "header") || [];
74
75
 
75
76
  const isFormData = requestBody && "content" in requestBody && requestBody.content?.["multipart/form-data"];
76
77
 
@@ -101,16 +102,18 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
101
102
  : "unknown";
102
103
 
103
104
  const urlWithParams =
104
- urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "encodeURIComponent(${data.$1})")}\`` : `"${path}"`;
105
+ urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${encodeURIComponent(data.$1)}")}\`` : `"${path}"`;
105
106
 
106
107
  const methodBody = [
107
108
  `${hasData ? "const { axiosConfig = {}, ...data } = props || {};" : "const { axiosConfig } = props || {};"}`,
108
109
  "const apiClient = getApiClient();",
109
110
  `const url = ${urlWithParams};`,
110
111
  queryParams.length > 0
111
- ? `const queryData = new URLSearchParams();
112
- ${queryParams.map((p) => `if (p.name) { queryData.append("${p.name}", encodeURIComponent(data["${p.name}"]));}`)}`
112
+ ? `const queryData = {
113
+ ${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
114
+ };`
113
115
  : "",
116
+
114
117
  requestBodySchema?.properties
115
118
  ? `const bodyData = {
116
119
  ${Object.entries(requestBodySchema.properties)
@@ -118,6 +121,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
118
121
  .join(",\n ")}
119
122
  };`
120
123
  : "",
124
+
121
125
  formDataSchema?.properties
122
126
  ? `const bodyData = new FormData();
123
127
  ${Object.entries(formDataSchema.properties)
@@ -136,6 +140,12 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
136
140
  isFormData
137
141
  ? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
138
142
  : "",
143
+ headerParams.length > 0
144
+ ? `const headerData = {
145
+ ${headerParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
146
+ };`
147
+ : "",
148
+ headerParams.length > 0 ? "axiosConfig.headers = { ...axiosConfig.headers, ...headerData };" : "",
139
149
  requestBody
140
150
  ? `const res = await apiClient.${method}<${responseType}>(url, ${formDataSchema?.properties || requestBodySchema?.properties ? "bodyData" : "data"}, axiosConfig);`
141
151
  : `const res = await apiClient.${method}<${responseType}>(url, axiosConfig);`,