axigen 1.1.0 → 1.2.1
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.
- package/README.md +78 -56
- package/dist/cli/index.mjs +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,10 @@ module.exports = {
|
|
|
56
56
|
|
|
57
57
|
language: "ts",
|
|
58
58
|
jsdoc: true,
|
|
59
|
+
functionName: {
|
|
60
|
+
transforms: [{ match: "-([a-zA-Z])", flags: "g", replacement: "upper:$1" }],
|
|
61
|
+
appendMethod: ["post", "put", "delete", "patch", "get", "head", "options"],
|
|
62
|
+
},
|
|
59
63
|
};
|
|
60
64
|
```
|
|
61
65
|
|
|
@@ -78,7 +82,8 @@ paths:
|
|
|
78
82
|
/users:
|
|
79
83
|
get:
|
|
80
84
|
operationId: getUsers
|
|
81
|
-
summary:
|
|
85
|
+
summary: Get user list
|
|
86
|
+
tags: [users]
|
|
82
87
|
parameters:
|
|
83
88
|
- name: page
|
|
84
89
|
in: query
|
|
@@ -88,74 +93,76 @@ paths:
|
|
|
88
93
|
in: query
|
|
89
94
|
schema:
|
|
90
95
|
type: integer
|
|
96
|
+
responses:
|
|
97
|
+
"200":
|
|
98
|
+
description: OK
|
|
99
|
+
content:
|
|
100
|
+
application/json:
|
|
101
|
+
schema:
|
|
102
|
+
type: object
|
|
103
|
+
properties:
|
|
104
|
+
data:
|
|
105
|
+
type: array
|
|
106
|
+
items:
|
|
107
|
+
$ref: "#/components/schemas/User"
|
|
108
|
+
total:
|
|
109
|
+
type: integer
|
|
91
110
|
|
|
92
111
|
/users/{userId}:
|
|
93
112
|
get:
|
|
94
113
|
operationId: getUserById
|
|
95
|
-
summary: Get
|
|
96
|
-
|
|
97
|
-
- name: userId
|
|
98
|
-
in: path
|
|
99
|
-
required: true
|
|
100
|
-
schema:
|
|
101
|
-
type: string
|
|
102
|
-
|
|
103
|
-
put:
|
|
104
|
-
operationId: updateUser
|
|
105
|
-
summary: Update a user
|
|
114
|
+
summary: Get user by ID
|
|
115
|
+
tags: [users]
|
|
106
116
|
parameters:
|
|
107
117
|
- name: userId
|
|
108
118
|
in: path
|
|
109
119
|
required: true
|
|
110
120
|
schema:
|
|
111
121
|
type: string
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
responses:
|
|
123
|
+
"200":
|
|
124
|
+
description: OK
|
|
125
|
+
content:
|
|
126
|
+
application/json:
|
|
127
|
+
schema:
|
|
128
|
+
$ref: "#/components/schemas/User"
|
|
118
129
|
```
|
|
119
130
|
|
|
120
131
|
axigen generates:
|
|
121
132
|
|
|
122
133
|
```ts
|
|
123
|
-
//
|
|
134
|
+
// This file is auto-generated by axigen. DO NOT EDIT.
|
|
135
|
+
// Generated at: 2026-06-25T18:37:24.080Z
|
|
124
136
|
|
|
125
|
-
import type { AxiosResponse } from "axios";
|
|
137
|
+
import type { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
126
138
|
import { axiosInstance } from "../lib/axios";
|
|
127
|
-
import type {
|
|
128
|
-
GetUsersQueryParams,
|
|
129
|
-
GetUsersResponse,
|
|
130
|
-
GetUserByIdPathParams,
|
|
131
|
-
GetUserByIdResponse,
|
|
132
|
-
UpdateUserPathParams,
|
|
133
|
-
UpdateUserBody,
|
|
134
|
-
UpdateUserResponse,
|
|
135
|
-
} from "./types";
|
|
139
|
+
import type { GetUserByIdPathParams, GetUserByIdResponse, GetUsersQueryParams, GetUsersResponse } from "./types";
|
|
136
140
|
|
|
137
141
|
/**
|
|
138
|
-
*
|
|
142
|
+
* Get user list
|
|
139
143
|
* `GET /users`
|
|
144
|
+
* @tags users
|
|
140
145
|
*/
|
|
141
|
-
export async function
|
|
142
|
-
|
|
146
|
+
export async function getUsersGet(
|
|
147
|
+
params?: GetUsersQueryParams,
|
|
148
|
+
config?: AxiosRequestConfig,
|
|
149
|
+
options?: AxiosRequestConfig,
|
|
150
|
+
): Promise<AxiosResponse<GetUsersResponse>> {
|
|
151
|
+
const mergedConfig: AxiosRequestConfig = { ...config, params: { ...params, ...config?.params } };
|
|
152
|
+
return axiosInstance({ method: "GET", url: "/users", ...mergedConfig }, options);
|
|
143
153
|
}
|
|
144
154
|
|
|
145
155
|
/**
|
|
146
|
-
* Get
|
|
156
|
+
* Get user by ID
|
|
147
157
|
* `GET /users/{userId}`
|
|
158
|
+
* @tags users
|
|
148
159
|
*/
|
|
149
|
-
export async function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* `PUT /users/{userId}`
|
|
156
|
-
*/
|
|
157
|
-
export async function updateUser(userId: UpdateUserPathParams["userId"], data: UpdateUserBody): Promise<AxiosResponse<UpdateUserResponse>> {
|
|
158
|
-
return axiosInstance.put(`/users/${userId}`, data);
|
|
160
|
+
export async function getUserByIdGet(
|
|
161
|
+
userId: GetUserByIdPathParams["userId"],
|
|
162
|
+
config?: AxiosRequestConfig,
|
|
163
|
+
options?: AxiosRequestConfig,
|
|
164
|
+
): Promise<AxiosResponse<GetUserByIdResponse>> {
|
|
165
|
+
return axiosInstance({ method: "GET", url: `/users/${userId}`, ...config }, options);
|
|
159
166
|
}
|
|
160
167
|
```
|
|
161
168
|
|
|
@@ -163,31 +170,44 @@ export async function updateUser(userId: UpdateUserPathParams["userId"], data: U
|
|
|
163
170
|
|
|
164
171
|
## Configuration
|
|
165
172
|
|
|
166
|
-
| Option
|
|
167
|
-
|
|
|
168
|
-
| `input`
|
|
169
|
-
| `output.client`
|
|
170
|
-
| `output.types`
|
|
171
|
-
| `axiosInstancePath`
|
|
172
|
-
| `axiosInstanceExport`
|
|
173
|
-
| `language`
|
|
174
|
-
| `jsdoc`
|
|
175
|
-
| `tags`
|
|
173
|
+
| Option | Type | Default | Description |
|
|
174
|
+
| --------------------------- | -------------- | --------------- | ------------------------------------------------------------------------ |
|
|
175
|
+
| `input` | `string` | — | Path to your OpenAPI spec file (YAML or JSON) |
|
|
176
|
+
| `output.client` | `string` | — | Output path for the generated client functions |
|
|
177
|
+
| `output.types` | `string` | — | Output path for generated TypeScript types (optional) |
|
|
178
|
+
| `axiosInstancePath` | `string` | — | Import path to your Axios instance |
|
|
179
|
+
| `axiosInstanceExport` | `string` | `axiosInstance` | Named export of your Axios instance |
|
|
180
|
+
| `language` | `'ts' \| 'js'` | `'ts'` | Output language |
|
|
181
|
+
| `jsdoc` | `boolean` | `true` | Add JSDoc comments to generated functions |
|
|
182
|
+
| `tags` | `string[]` | — | Only generate endpoints matching these tags |
|
|
183
|
+
| `functionName` | `object` | — | Control generated function name transforms and method suffix (see below) |
|
|
184
|
+
| `functionName.transforms` | `Transform[]` | `[]` | Array of regex transform rules applied to the operationId |
|
|
185
|
+
| `functionName.appendMethod` | `string[]` | `[]` | HTTP methods whose name is appended as a suffix to the function name |
|
|
176
186
|
|
|
177
187
|
### Axios Instance
|
|
178
188
|
|
|
179
|
-
axigen does not create an Axios instance for you — it imports the one you already have in your project.
|
|
189
|
+
axigen does not create an Axios instance for you — it imports the one you already have in your project. The generated functions expect your instance to follow this call signature:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
axiosInstance(config: AxiosRequestConfig, options?: AxiosRequestConfig): Promise<AxiosResponse>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
This is intentional: it lets you intercept or merge options at the instance level (e.g. passing per-request auth headers or timeout overrides as a second argument), keeping generated code decoupled from your instance's internal logic.
|
|
196
|
+
|
|
197
|
+
A typical instance looks like this:
|
|
180
198
|
|
|
181
199
|
```ts
|
|
182
200
|
// src/lib/axios.ts
|
|
183
|
-
import axios from "axios";
|
|
201
|
+
import axios, { type AxiosRequestConfig } from "axios";
|
|
184
202
|
|
|
185
|
-
|
|
203
|
+
const instance = axios.create({
|
|
186
204
|
baseURL: "https://api.example.com/v1",
|
|
187
205
|
headers: {
|
|
188
206
|
"Content-Type": "application/json",
|
|
189
207
|
},
|
|
190
208
|
});
|
|
209
|
+
|
|
210
|
+
export const axiosInstance = (config: AxiosRequestConfig, options?: AxiosRequestConfig) => instance({ ...config, ...options });
|
|
191
211
|
```
|
|
192
212
|
|
|
193
213
|
Then in your config:
|
|
@@ -197,6 +217,8 @@ axiosInstancePath: '../lib/axios',
|
|
|
197
217
|
axiosInstanceExport: 'axiosInstance', // default, can be omitted
|
|
198
218
|
```
|
|
199
219
|
|
|
220
|
+
> **Note:** If you use a plain `axios.create()` instance without the two-argument wrapper, the `options` parameter passed by generated functions will be ignored. The wrapper pattern above is the recommended approach.
|
|
221
|
+
|
|
200
222
|
---
|
|
201
223
|
|
|
202
224
|
## CLI
|
package/dist/cli/index.mjs
CHANGED
|
@@ -623,6 +623,10 @@ module.exports = {
|
|
|
623
623
|
axiosInstancePath: '../lib/axios',
|
|
624
624
|
language: 'ts',
|
|
625
625
|
jsdoc: true,
|
|
626
|
+
functionName: {
|
|
627
|
+
transforms: [{ match: "-([a-zA-Z])", flags: "g", replacement: "upper:$1" }],
|
|
628
|
+
appendMethod: ["post", "put", "delete", "patch", "get", "head", "options"],
|
|
629
|
+
},
|
|
626
630
|
}
|
|
627
631
|
`;
|
|
628
632
|
fs4.writeFileSync(dest, template, "utf-8");
|