axigen 1.2.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 +28 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,31 +170,44 @@ export async function getUserByIdGet(
|
|
|
170
170
|
|
|
171
171
|
## Configuration
|
|
172
172
|
|
|
173
|
-
| Option
|
|
174
|
-
|
|
|
175
|
-
| `input`
|
|
176
|
-
| `output.client`
|
|
177
|
-
| `output.types`
|
|
178
|
-
| `axiosInstancePath`
|
|
179
|
-
| `axiosInstanceExport`
|
|
180
|
-
| `language`
|
|
181
|
-
| `jsdoc`
|
|
182
|
-
| `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 |
|
|
183
186
|
|
|
184
187
|
### Axios Instance
|
|
185
188
|
|
|
186
|
-
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:
|
|
187
198
|
|
|
188
199
|
```ts
|
|
189
200
|
// src/lib/axios.ts
|
|
190
|
-
import axios from "axios";
|
|
201
|
+
import axios, { type AxiosRequestConfig } from "axios";
|
|
191
202
|
|
|
192
|
-
|
|
203
|
+
const instance = axios.create({
|
|
193
204
|
baseURL: "https://api.example.com/v1",
|
|
194
205
|
headers: {
|
|
195
206
|
"Content-Type": "application/json",
|
|
196
207
|
},
|
|
197
208
|
});
|
|
209
|
+
|
|
210
|
+
export const axiosInstance = (config: AxiosRequestConfig, options?: AxiosRequestConfig) => instance({ ...config, ...options });
|
|
198
211
|
```
|
|
199
212
|
|
|
200
213
|
Then in your config:
|
|
@@ -204,6 +217,8 @@ axiosInstancePath: '../lib/axios',
|
|
|
204
217
|
axiosInstanceExport: 'axiosInstance', // default, can be omitted
|
|
205
218
|
```
|
|
206
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
|
+
|
|
207
222
|
---
|
|
208
223
|
|
|
209
224
|
## CLI
|