react-query-lightbase-codegen 2.5.7 → 2.5.9
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.
|
@@ -63,6 +63,11 @@ function generateAxiosMethod(operation, spec) {
|
|
|
63
63
|
requestBody.content?.["application/json;charset=UTF-8"]?.schema)
|
|
64
64
|
: undefined;
|
|
65
65
|
const requestBodySchema = content ? resolveSchema(content, spec) : undefined;
|
|
66
|
+
// Check if request body is a primitive type (string, number, boolean)
|
|
67
|
+
const isPrimitiveRequestBody = requestBodySchema &&
|
|
68
|
+
!requestBodySchema.properties &&
|
|
69
|
+
!requestBodySchema.type?.includes("object") &&
|
|
70
|
+
!requestBodySchema.type?.includes("array");
|
|
66
71
|
// Add request body type if it exists
|
|
67
72
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
68
73
|
const namedType = (0, utils_1.pascalCase)(operationId);
|
|
@@ -71,8 +76,14 @@ function generateAxiosMethod(operation, spec) {
|
|
|
71
76
|
? `T.${`${namedType}Response${responseDetails[0]}`}`
|
|
72
77
|
: "unknown";
|
|
73
78
|
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${encodeURIComponent(data.$1)}")}\`` : `"${path}"`;
|
|
79
|
+
// Handle destructuring based on whether we have primitive request body
|
|
80
|
+
const destructuringLine = hasData
|
|
81
|
+
? isPrimitiveRequestBody
|
|
82
|
+
? "const { axiosConfig = {}, data } = props || {};"
|
|
83
|
+
: "const { axiosConfig = {}, ...data } = props || {};"
|
|
84
|
+
: "const { axiosConfig } = props || {};";
|
|
74
85
|
const methodBody = [
|
|
75
|
-
|
|
86
|
+
destructuringLine,
|
|
76
87
|
"const apiClient = getApiClient();",
|
|
77
88
|
`const url = ${urlWithParams};`,
|
|
78
89
|
queryParams.length > 0
|
|
@@ -94,9 +105,9 @@ function generateAxiosMethod(operation, spec) {
|
|
|
94
105
|
const schemaProperty = prop;
|
|
95
106
|
const isBinary = schemaProperty.format === "binary";
|
|
96
107
|
return formDataSchema?.required?.includes(key)
|
|
97
|
-
? `bodyData.append("${key}", ${isBinary ? "" : "String("}
|
|
98
|
-
: `if (
|
|
99
|
-
bodyData.append("${key}", ${isBinary ? "" : "String("}
|
|
108
|
+
? `bodyData.append("${key}", ${isBinary ? "" : "String("}data.${key}${isBinary ? "" : ")"});`
|
|
109
|
+
: `if (data.${key} != null) {
|
|
110
|
+
bodyData.append("${key}", ${isBinary ? "" : "String("}data.${key}${isBinary ? "" : ")"});
|
|
100
111
|
}`;
|
|
101
112
|
})
|
|
102
113
|
.join("\n ")}`
|
|
@@ -122,7 +133,9 @@ function generateAxiosMethod(operation, spec) {
|
|
|
122
133
|
// ${requestBody ? `data: ${isFormData ? "formData" : "bodyData"},` : ""}
|
|
123
134
|
// ${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig"}
|
|
124
135
|
const requestParms = hasData
|
|
125
|
-
?
|
|
136
|
+
? isPrimitiveRequestBody
|
|
137
|
+
? `props: { data: T.${(0, utils_1.pascalCase)(operationId)}Params; axiosConfig?: AxiosRequestConfig; }`
|
|
138
|
+
: `props: T.${(0, utils_1.pascalCase)(operationId)}Params & { axiosConfig?: AxiosRequestConfig; }`
|
|
126
139
|
: "props?: { axiosConfig?: AxiosRequestConfig }";
|
|
127
140
|
return `
|
|
128
141
|
${jsDocLines.join("\n ")}
|
|
@@ -72,6 +72,8 @@ function generateTypeDefinitions(spec) {
|
|
|
72
72
|
[]);
|
|
73
73
|
const queryParams = (parameters?.filter((p) => "in" in p && p.in === "query") ||
|
|
74
74
|
[]);
|
|
75
|
+
const headerParams = (parameters?.filter((p) => "in" in p && p.in === "header") ||
|
|
76
|
+
[]);
|
|
75
77
|
// Add path and query parameters
|
|
76
78
|
urlParams.forEach((p) => {
|
|
77
79
|
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
@@ -93,6 +95,16 @@ function generateTypeDefinitions(spec) {
|
|
|
93
95
|
: "";
|
|
94
96
|
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
95
97
|
});
|
|
98
|
+
headerParams.forEach((p) => {
|
|
99
|
+
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
100
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
101
|
+
const hasDescription = "description" in p && p.description;
|
|
102
|
+
const desc = hasDescription || isDeprecated
|
|
103
|
+
? `\n/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
104
|
+
*/\n`
|
|
105
|
+
: "";
|
|
106
|
+
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
107
|
+
});
|
|
96
108
|
// Add request body type if it exists
|
|
97
109
|
const hasData = (parameters && parameters.length > 0) || requestBody;
|
|
98
110
|
let dataType = "undefined";
|
package/package.json
CHANGED
|
@@ -89,6 +89,13 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
89
89
|
|
|
90
90
|
const requestBodySchema = content ? resolveSchema(content, spec) : undefined;
|
|
91
91
|
|
|
92
|
+
// Check if request body is a primitive type (string, number, boolean)
|
|
93
|
+
const isPrimitiveRequestBody =
|
|
94
|
+
requestBodySchema &&
|
|
95
|
+
!requestBodySchema.properties &&
|
|
96
|
+
!requestBodySchema.type?.includes("object") &&
|
|
97
|
+
!requestBodySchema.type?.includes("array");
|
|
98
|
+
|
|
92
99
|
// Add request body type if it exists
|
|
93
100
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
94
101
|
|
|
@@ -104,8 +111,15 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
104
111
|
const urlWithParams =
|
|
105
112
|
urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${encodeURIComponent(data.$1)}")}\`` : `"${path}"`;
|
|
106
113
|
|
|
114
|
+
// Handle destructuring based on whether we have primitive request body
|
|
115
|
+
const destructuringLine = hasData
|
|
116
|
+
? isPrimitiveRequestBody
|
|
117
|
+
? "const { axiosConfig = {}, data } = props || {};"
|
|
118
|
+
: "const { axiosConfig = {}, ...data } = props || {};"
|
|
119
|
+
: "const { axiosConfig } = props || {};";
|
|
120
|
+
|
|
107
121
|
const methodBody = [
|
|
108
|
-
|
|
122
|
+
destructuringLine,
|
|
109
123
|
"const apiClient = getApiClient();",
|
|
110
124
|
`const url = ${urlWithParams};`,
|
|
111
125
|
queryParams.length > 0
|
|
@@ -129,9 +143,9 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
129
143
|
const schemaProperty = prop as OpenAPIV3.SchemaObject;
|
|
130
144
|
const isBinary = schemaProperty.format === "binary";
|
|
131
145
|
return formDataSchema?.required?.includes(key)
|
|
132
|
-
? `bodyData.append("${key}", ${isBinary ? "" : "String("}
|
|
133
|
-
: `if (
|
|
134
|
-
bodyData.append("${key}", ${isBinary ? "" : "String("}
|
|
146
|
+
? `bodyData.append("${key}", ${isBinary ? "" : "String("}data.${key}${isBinary ? "" : ")"});`
|
|
147
|
+
: `if (data.${key} != null) {
|
|
148
|
+
bodyData.append("${key}", ${isBinary ? "" : "String("}data.${key}${isBinary ? "" : ")"});
|
|
135
149
|
}`;
|
|
136
150
|
})
|
|
137
151
|
.join("\n ")}`
|
|
@@ -159,7 +173,9 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
159
173
|
// ${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig"}
|
|
160
174
|
|
|
161
175
|
const requestParms = hasData
|
|
162
|
-
?
|
|
176
|
+
? isPrimitiveRequestBody
|
|
177
|
+
? `props: { data: T.${pascalCase(operationId)}Params; axiosConfig?: AxiosRequestConfig; }`
|
|
178
|
+
: `props: T.${pascalCase(operationId)}Params & { axiosConfig?: AxiosRequestConfig; }`
|
|
163
179
|
: "props?: { axiosConfig?: AxiosRequestConfig }";
|
|
164
180
|
|
|
165
181
|
return `
|
|
@@ -89,6 +89,8 @@ export function generateTypeDefinitions(spec: OpenAPIV3.Document): string {
|
|
|
89
89
|
[]) as OpenAPIV3.ParameterObject[];
|
|
90
90
|
const queryParams = (parameters?.filter((p) => "in" in p && p.in === "query") ||
|
|
91
91
|
[]) as OpenAPIV3.ParameterObject[];
|
|
92
|
+
const headerParams = (parameters?.filter((p) => "in" in p && p.in === "header") ||
|
|
93
|
+
[]) as OpenAPIV3.ParameterObject[];
|
|
92
94
|
|
|
93
95
|
// Add path and query parameters
|
|
94
96
|
urlParams.forEach((p) => {
|
|
@@ -114,6 +116,19 @@ export function generateTypeDefinitions(spec: OpenAPIV3.Document): string {
|
|
|
114
116
|
: "";
|
|
115
117
|
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${getTypeFromSchema(p.schema)}`);
|
|
116
118
|
});
|
|
119
|
+
|
|
120
|
+
headerParams.forEach((p) => {
|
|
121
|
+
const safeName = sanitizePropertyName(p.name);
|
|
122
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
123
|
+
const hasDescription = "description" in p && p.description;
|
|
124
|
+
const desc =
|
|
125
|
+
hasDescription || isDeprecated
|
|
126
|
+
? `\n/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
127
|
+
*/\n`
|
|
128
|
+
: "";
|
|
129
|
+
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${getTypeFromSchema(p.schema)}`);
|
|
130
|
+
});
|
|
131
|
+
|
|
117
132
|
// Add request body type if it exists
|
|
118
133
|
const hasData = (parameters && parameters.length > 0) || requestBody;
|
|
119
134
|
|