Skip to content

Commit 7ec9012

Browse files
committed
refactor: improve Axios method handling and update React Query generator
This commit includes: - Changed the Axios method return to store the response in a variable before returning the data. - Updated the React Query generator to adjust the parameter definition for better clarity. - Cleaned up formatting in package.json for consistency.
1 parent d11263c commit 7ec9012

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"license": "MIT",
55
"description": "Generate Axios API clients and React Query options from OpenAPI specifications",
66
"exports": "./dist/index.js",
7-
"files": [
8-
"src",
9-
"dist"
10-
],
7+
"files": ["src", "dist"],
118
"author": {
129
"name": "Oliver Winter",
1310
"email": "[email protected]"

src/generator/clientGenerator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
143143
})
144144
.join("\n ")}`
145145
: "",
146-
`return apiClient.${method}<${responseType}>(url, {
146+
`const res = await apiClient.${method}<${responseType}>(url, {
147147
${queryParams.length > 0 ? "params: queryData," : ""}
148148
${requestBody ? `data: ${isFormData ? "formData" : "bodyData"},` : ""}
149149
${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...config?.headers }, ...config },` : "...config"}
150-
});`,
150+
});
151+
return res.data;`,
151152
]
152153
.filter(Boolean)
153154
.join("\n ");

src/generator/reactQueryGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OpenAPIV3 } from "openapi-types";
2-
import { camelCase, pascalCase, sanitizeTypeName, specTitle } from "../utils";
2+
import { camelCase, specTitle } from "../utils";
33
import type { OperationInfo } from "./clientGenerator";
44

55
function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document): string {
@@ -40,7 +40,7 @@ function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document
4040

4141
return `
4242
export const ${namedQueryOptions} = (
43-
${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
43+
${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_?: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
4444
) => {
4545
const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
4646
return queryOptions({

0 commit comments

Comments
 (0)