@moccona/apicodegen 0.1.2 β 1.0.0
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 +312 -29
- package/bin/cli.cjs +9 -6
- package/npm/index.cjs +1279 -311
- package/npm/index.cjs.map +1 -1
- package/npm/index.d.cts +293 -51
- package/npm/index.d.cts.map +1 -1
- package/npm/index.d.mts +293 -51
- package/npm/index.d.mts.map +1 -1
- package/npm/index.mjs +1271 -310
- package/npm/index.mjs.map +1 -1
- package/npm/vite/index.d.mts +27 -10
- package/npm/vite/index.d.mts.map +1 -1
- package/npm/vite/index.mjs +1259 -306
- package/npm/vite/index.mjs.map +1 -1
- package/package.json +36 -20
package/README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# @moccona/apicodegen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The minimal, zero-config OpenAPI β TypeScript client generator. One output
|
|
4
|
+
file, no runtime dependencies, native Vite plugin, and a `--check` mode built
|
|
5
|
+
for CI. Generated code is predictable and JSDoc-rich, so it works well for
|
|
6
|
+
humans and AI assistants alike.
|
|
7
|
+
|
|
8
|
+
New here? See [How apicodegen compares](docs/comparison.md) and
|
|
9
|
+
[Upgrading from 0.1.x](docs/UPGRADING.md).
|
|
4
10
|
|
|
5
11
|
[](https://www.npmjs.com/package/@moccona/apicodegen)
|
|
6
12
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://nodejs.org)
|
|
14
|
+
[](https://github.com/freemode1614/api-codegen)
|
|
9
15
|
[](https://github.com/freemode1614/api-codegen)
|
|
10
16
|
|
|
11
17
|
---
|
|
@@ -17,6 +23,7 @@ A powerful OpenAPI code generator that automatically generates TypeScript API cl
|
|
|
17
23
|
- [Installation](#-installation)
|
|
18
24
|
- [CLI Usage](#-cli-usage)
|
|
19
25
|
- [Vite Plugin](#-vite-plugin)
|
|
26
|
+
- [Bring Your Own HTTP Client](#bring-your-own-http-client)
|
|
20
27
|
- [Generated Code](#-generated-code)
|
|
21
28
|
- [Supported Features](#-supported-features)
|
|
22
29
|
- [Examples](#-examples)
|
|
@@ -30,9 +37,12 @@ A powerful OpenAPI code generator that automatically generates TypeScript API cl
|
|
|
30
37
|
|
|
31
38
|
| Feature | Description |
|
|
32
39
|
|---------|-------------|
|
|
33
|
-
| **Multi-version Support** |
|
|
40
|
+
| **Multi-version Support** | Core support for OpenAPI 2.0, 3.0, and 3.1 (see [Roadmap](ROADMAP.md) for gaps) |
|
|
41
|
+
| **JSON and YAML Specs** | Local files and remote URLs, with structured parse errors |
|
|
34
42
|
| **TypeScript First** | Generates complete type definitions and type-safe API functions |
|
|
35
43
|
| **Multiple Adaptors** | Built-in `fetch` and `axios` HTTP client support |
|
|
44
|
+
| **Auto Base URL** | Uses the spec's first `servers` entry (or V2 `host`) when `baseURL` is omitted |
|
|
45
|
+
| **Typed Response Maps** | 2xx return type plus an exported map of every declared status code |
|
|
36
46
|
| **CLI Tool** | Simple command-line interface with retro ASCII banner |
|
|
37
47
|
| **Vite Plugin** | Seamless integration into Vite build workflow |
|
|
38
48
|
| **File Upload** | Native support for multipart/form-data file uploads |
|
|
@@ -41,6 +51,9 @@ A powerful OpenAPI code generator that automatically generates TypeScript API cl
|
|
|
41
51
|
### Key Highlights
|
|
42
52
|
|
|
43
53
|
- **Zero Runtime Dependencies** - Lightweight generated code with no external runtime
|
|
54
|
+
- **Zero Config** - A spec path and an output path are enough; the server URL comes from the spec
|
|
55
|
+
- **AI Friendly** - Predictable names, JSDoc from the spec, and one file that is easy to read or patch
|
|
56
|
+
- **CI Friendly** - `--check` fails the build when the committed client drifts, without writing files
|
|
44
57
|
- **Type-safe** - Full TypeScript support with strict type inference
|
|
45
58
|
- **Circular Reference Handling** - Properly handles `$ref` loops in OpenAPI schemas
|
|
46
59
|
- **JSDoc Generation** - Automatic documentation from OpenAPI descriptions
|
|
@@ -95,9 +108,21 @@ pnpm add -D @moccona/apicodegen
|
|
|
95
108
|
| `--output` | `-o` | Output file path | `./output.ts` |
|
|
96
109
|
| `--spec` | `-s` | OpenAPI spec file path or URL | Required |
|
|
97
110
|
| `--adaptor` | `-a` | HTTP client (`fetch` or `axios`) | `fetch` |
|
|
98
|
-
| `--
|
|
111
|
+
| `--importClientSource` | | Import line prepended to the output; required when `--adaptor axios` | none |
|
|
112
|
+
| `--baseURL` | `-b` | API base URL; `""` disables server-URL inference (default: the spec's first server) | - |
|
|
113
|
+
| `--error-mode` | | Non-2xx handling (`throw` or `result`) | as-is |
|
|
114
|
+
| `--split-by` | | Split output (`tag`); `--output` becomes a directory | single file |
|
|
115
|
+
| `--include-tags` | | Only generate operations with these comma-separated tags | all |
|
|
116
|
+
| `--exclude-tags` | | Skip operations with these comma-separated tags | none |
|
|
117
|
+
| `--include-paths` | | Only generate paths with these comma-separated prefixes | all |
|
|
118
|
+
| `--exclude-paths` | | Skip paths with these comma-separated prefixes | none |
|
|
119
|
+
| `--header` | | Extra header for spec fetch, `"Key: Value"` (repeatable) | none |
|
|
120
|
+
| `--timeout` | | Spec fetch timeout in milliseconds | - |
|
|
121
|
+
| `--insecure` | | Skip TLS verification when fetching the spec | `false` |
|
|
99
122
|
| `--config` | `-c` | Path to config file | - |
|
|
100
123
|
| `--watch` | `-w` | Watch for file changes | `false` |
|
|
124
|
+
| `--check` | | Exit non-zero if output is out of date; never writes | `false` |
|
|
125
|
+
| `--typecheck` | | Type-check the generated output | `false` |
|
|
101
126
|
| `--verbose` | `-v` | Enable verbose logging | `false` |
|
|
102
127
|
|
|
103
128
|
### Examples
|
|
@@ -109,18 +134,189 @@ apicodegen https://api.example.com/openapi.json -o ./src/api.ts
|
|
|
109
134
|
# From local file
|
|
110
135
|
apicodegen ./docs/openapi.json -o ./src/generated/api.ts
|
|
111
136
|
|
|
112
|
-
# With axios and custom baseURL
|
|
113
|
-
apicodegen ./openapi.json -a axios
|
|
137
|
+
# With axios and custom baseURL (provide the client import, see "Bring Your Own HTTP Client")
|
|
138
|
+
apicodegen ./openapi.json -a axios \
|
|
139
|
+
--importClientSource "import axios from 'axios'" \
|
|
140
|
+
-b https://api.example.com -o ./src/api.ts
|
|
114
141
|
|
|
115
142
|
# Watch mode for development
|
|
116
|
-
apicodegen ./openapi.
|
|
143
|
+
apicodegen ./openapi.json -w -o ./src/api.ts -v
|
|
144
|
+
|
|
145
|
+
# One file per tag: types.ts, pets.ts, store.ts, index.ts
|
|
146
|
+
apicodegen ./openapi.json --split-by tag -o ./src/api
|
|
147
|
+
|
|
148
|
+
# Type-check the generated client
|
|
149
|
+
apicodegen ./openapi.json -o ./src/api.ts --typecheck
|
|
150
|
+
|
|
151
|
+
# CI: fail when the committed client is out of date
|
|
152
|
+
apicodegen ./openapi.json -o ./src/api.ts --check
|
|
153
|
+
|
|
154
|
+
# Authenticated, slow, or self-signed spec URL
|
|
155
|
+
apicodegen https://internal.example.com/openapi.json \
|
|
156
|
+
--header "Authorization: Bearer $TOKEN" \
|
|
157
|
+
--timeout 30000 --insecure \
|
|
158
|
+
-o ./src/api.ts
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### CI drift check
|
|
162
|
+
|
|
163
|
+
Run generation with `--check` instead of writing. It compares the committed
|
|
164
|
+
client with a fresh generation and exits non-zero when it is missing or stale:
|
|
165
|
+
|
|
166
|
+
```yaml
|
|
167
|
+
# .github/workflows/api.yml
|
|
168
|
+
- uses: actions/checkout@v6
|
|
169
|
+
- uses: actions/setup-node@v6
|
|
170
|
+
with:
|
|
171
|
+
node-version: 22.18
|
|
172
|
+
- run: npx @moccona/apicodegen ./openapi.json -o ./src/api.ts --check
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
With `--split-by tag`, point `--output` at the directory; every generated file
|
|
176
|
+
is compared.
|
|
177
|
+
|
|
178
|
+
### Config file
|
|
179
|
+
|
|
180
|
+
`apicodegen.config.{json,js,mjs,ts}` (or `package.json` β `apicodegen`) is
|
|
181
|
+
loaded automatically; precedence is defaults < env < config file < CLI.
|
|
182
|
+
TypeScript configs use Node 22.18+'s native type stripping, so keep them to
|
|
183
|
+
erasable syntax (no enums/namespaces).
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
// apicodegen.config.ts β one API
|
|
187
|
+
export default { spec: './openapi.json', output: './src/api.ts' };
|
|
117
188
|
```
|
|
118
189
|
|
|
190
|
+
```ts
|
|
191
|
+
// apicodegen.config.ts β multiple APIs
|
|
192
|
+
export default {
|
|
193
|
+
output: './src/api', // shared default
|
|
194
|
+
specs: [
|
|
195
|
+
{ name: 'pets', spec: './pets.json', output: './src/pets.ts' },
|
|
196
|
+
{ name: 'store', spec: './store.json', splitBy: 'tag' },
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`--spec` / `--output` are ignored when more than one entry is defined.
|
|
202
|
+
|
|
203
|
+
### Error handling
|
|
204
|
+
|
|
205
|
+
By default `fetch` clients return the response as-is and `axios` keeps its
|
|
206
|
+
default reject-on-non-2xx behaviour. Set `--error-mode` (or `errorMode` in
|
|
207
|
+
config) for an explicit contract:
|
|
208
|
+
|
|
209
|
+
- `throw` β rejects with an `Error` carrying `status` and the raw `body` text.
|
|
210
|
+
- `result` β resolves `{ ok: true, status, data }` or `{ ok: false, status, error }`.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
apicodegen ./openapi.json --error-mode result -o ./src/api.ts
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Authentication
|
|
217
|
+
|
|
218
|
+
When the spec declares `securitySchemes` (or Swagger 2.0
|
|
219
|
+
`securityDefinitions`), secured operations get an extra optional `auth`
|
|
220
|
+
argument:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
export type AuthOptions = {
|
|
224
|
+
[scheme: string]: string | { username: string; password: string };
|
|
225
|
+
};
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- `apiKey` β sent as a header, query parameter or cookie using the scheme's `name`.
|
|
229
|
+
- `http` bearer / `oauth2` / `openIdConnect` β `Authorization: Bearer <token>`.
|
|
230
|
+
- `http` basic β `Authorization: Basic <base64>` from `{ username, password }`.
|
|
231
|
+
|
|
232
|
+
The same call shape works for both adaptors:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
await getPet({ petId: '1' }, { BearerAuth: 'token' });
|
|
236
|
+
await getPet({ petId: '1' }, { BasicAuth: { username: 'u', password: 'p' } });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Only credentials you pass are injected; omitting `auth` sends the request
|
|
240
|
+
unauthenticated. Operations that opt out with `security: []` get no `auth`
|
|
241
|
+
argument.
|
|
242
|
+
|
|
243
|
+
### Request control
|
|
244
|
+
|
|
245
|
+
Every generated function takes an optional trailing `options` argument:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
export type RequestOptions = {
|
|
249
|
+
signal?: AbortSignal;
|
|
250
|
+
headers?: Record<string, string>;
|
|
251
|
+
timeout?: number;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
await getPet({ petId: '1' }, { signal: controller.signal, timeout: 5_000 });
|
|
255
|
+
await getPet({ petId: '1' }, { headers: { 'X-Request-Id': requestId } });
|
|
256
|
+
await getPet({ petId: '1' }, { BearerAuth: 'token' }, { timeout: 5_000 });
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
- `headers` are merged over generated ones, so callers can override or add.
|
|
260
|
+
- For `fetch`, `timeout` and `signal` are combined with `AbortSignal.any`;
|
|
261
|
+
either one alone works.
|
|
262
|
+
- For `axios`, `signal` and `timeout` map to the native axios config.
|
|
263
|
+
|
|
264
|
+
### Request and response types
|
|
265
|
+
|
|
266
|
+
Schemas that use `readOnly` / `writeOnly` get two extra exported aliases:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
export type Pet = { id: number; name: string; secret?: string };
|
|
270
|
+
export type PetInput = { name: string; secret?: string }; // no readOnly id
|
|
271
|
+
export type PetOutput = { id: number; name: string }; // no writeOnly secret
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Generated request bodies use the input shape (and the response cast uses the
|
|
275
|
+
output shape), following nested `$ref`s. The original `Pet` type is unchanged.
|
|
276
|
+
Variants are only created when the name is free; otherwise the original schema
|
|
277
|
+
is used.
|
|
278
|
+
|
|
279
|
+
### Filtering operations
|
|
280
|
+
|
|
281
|
+
Generate only part of a large spec with tag and path filters:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Only the pets tag, and only /v1 paths
|
|
285
|
+
apicodegen ./openapi.json --include-tags pets --include-paths /v1 -o ./src/api.ts
|
|
286
|
+
|
|
287
|
+
# Everything except admin endpoints
|
|
288
|
+
apicodegen ./openapi.json --exclude-tags admin --exclude-paths /admin -o ./src/api.ts
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Config equivalents are `includeTags`, `excludeTags`, `includePaths`, and
|
|
292
|
+
`excludePaths` (string arrays). Paths match by prefix. With `includeTags`,
|
|
293
|
+
operations that have no tags are skipped; filters combine (include first, then
|
|
294
|
+
exclude).
|
|
295
|
+
|
|
296
|
+
### Multi-file output
|
|
297
|
+
|
|
298
|
+
`--split-by tag` (config `splitBy: 'tag'`, env `APICODEGEN_SPLIT_BY=tag`)
|
|
299
|
+
treats `--output` as a directory and writes:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
src/api/
|
|
303
|
+
index.ts # re-exports types and every tag file
|
|
304
|
+
types.ts # enums and schema type aliases
|
|
305
|
+
pets.ts # functions tagged "pets"
|
|
306
|
+
store.ts # functions tagged "store"
|
|
307
|
+
default.ts # operations without tags
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Each tag file imports shared types from `./types.js`; operations keep their
|
|
311
|
+
first tag as the file name. The Vite plugin writes the same files next to its
|
|
312
|
+
`output` path.
|
|
313
|
+
|
|
119
314
|
---
|
|
120
315
|
|
|
121
316
|
## π Vite Plugin
|
|
122
317
|
|
|
123
|
-
|
|
318
|
+
Generation runs in `buildStart`. In dev, the plugin watches each local spec
|
|
319
|
+
and triggers a full reload after regenerating.
|
|
124
320
|
|
|
125
321
|
```typescript
|
|
126
322
|
// vite.config.ts
|
|
@@ -132,7 +328,7 @@ export default defineConfig({
|
|
|
132
328
|
apiCodeGenPlugin([
|
|
133
329
|
{
|
|
134
330
|
name: 'petstore-api',
|
|
135
|
-
|
|
331
|
+
spec: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
136
332
|
output: './src/api/petstore.ts',
|
|
137
333
|
adaptor: 'fetch',
|
|
138
334
|
baseURL: 'https://petstore3.swagger.io/api/v3',
|
|
@@ -151,8 +347,14 @@ export default defineConfig({
|
|
|
151
347
|
| `docURL` | `string` | Yes* | OpenAPI document URL (alias for `spec`) |
|
|
152
348
|
| `output` | `string` | Yes | Output file path |
|
|
153
349
|
| `adaptor` | `'fetch' \| 'axios'` | No | HTTP client (default: `fetch`) |
|
|
350
|
+
| `errorMode` | `'throw' \| 'result'` | No | Non-2xx handling (default: leave response as-is) |
|
|
351
|
+
| `splitBy` | `'tag'` | No | Write `types.ts` + one file per tag next to `output` |
|
|
352
|
+
| `includeTags` | `string[]` | No | Only generate operations carrying one of these tags |
|
|
353
|
+
| `excludeTags` | `string[]` | No | Skip operations carrying one of these tags |
|
|
354
|
+
| `includePaths` | `string[]` | No | Only generate paths starting with one of these prefixes |
|
|
355
|
+
| `excludePaths` | `string[]` | No | Skip paths starting with one of these prefixes |
|
|
154
356
|
| `baseURL` | `string` | No | API base URL |
|
|
155
|
-
| `importClientSource` | `string` | No |
|
|
357
|
+
| `importClientSource` | `string` | No | Import line prepended to the output; required for the `axios` adaptor (see below) |
|
|
156
358
|
| `verbose` | `boolean` | No | Enable verbose logging |
|
|
157
359
|
| `typeCheck` | `boolean` | No | Run type check after generation |
|
|
158
360
|
|
|
@@ -178,7 +380,6 @@ apiClient.interceptors.request.use((config) => {
|
|
|
178
380
|
```typescript
|
|
179
381
|
// vite.config.ts
|
|
180
382
|
import { apiCodeGenPlugin } from '@moccona/apicodegen/vite';
|
|
181
|
-
import { apiClient } from './src/lib/api-client';
|
|
182
383
|
|
|
183
384
|
export default defineConfig({
|
|
184
385
|
plugins: [
|
|
@@ -188,6 +389,8 @@ export default defineConfig({
|
|
|
188
389
|
spec: './openapi.json',
|
|
189
390
|
output: './src/api/generated.ts',
|
|
190
391
|
adaptor: 'axios',
|
|
392
|
+
// Keep generated paths relative so the instance baseURL applies.
|
|
393
|
+
baseURL: '',
|
|
191
394
|
importClientSource: `import { apiClient as axios } from '@/lib/api-client';`,
|
|
192
395
|
},
|
|
193
396
|
]),
|
|
@@ -195,16 +398,87 @@ export default defineConfig({
|
|
|
195
398
|
});
|
|
196
399
|
```
|
|
197
400
|
|
|
198
|
-
Generated code will use your custom instance
|
|
401
|
+
Generated code will use your custom instance (aliased to `axios`, the identifier
|
|
402
|
+
the `axios` adaptor emits):
|
|
199
403
|
|
|
200
404
|
```typescript
|
|
201
405
|
import { apiClient as axios } from '@/lib/api-client';
|
|
202
406
|
|
|
203
407
|
export async function getPetById({ petId }: { petId: number }) {
|
|
204
|
-
return
|
|
408
|
+
return axios(`/pets/${petId}`, { method: 'GET' });
|
|
205
409
|
}
|
|
206
410
|
```
|
|
207
411
|
|
|
412
|
+
## Bring Your Own HTTP Client
|
|
413
|
+
|
|
414
|
+
The generator does not import an HTTP client for you. `adaptor` selects the call
|
|
415
|
+
shape, and the generated code calls a fixed identifier:
|
|
416
|
+
|
|
417
|
+
| Adaptor | Generated call | Identifier the output expects |
|
|
418
|
+
|---------|----------------|-------------------------------|
|
|
419
|
+
| `fetch` | `fetch(url, init)` | `fetch` (global by default) |
|
|
420
|
+
| `axios` | `axios<T>(url, config)` | `axios` |
|
|
421
|
+
|
|
422
|
+
**Recommended: a configured axios instance.** Put `baseURL`, timeout,
|
|
423
|
+
interceptors and auth on the instance, then import it under the `axios` name:
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
// src/lib/api-client.ts
|
|
427
|
+
import axios from 'axios';
|
|
428
|
+
|
|
429
|
+
export const apiClient = axios.create({
|
|
430
|
+
baseURL: 'https://api.example.com',
|
|
431
|
+
timeout: 10_000,
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
// apicodegen.config.ts
|
|
437
|
+
export default {
|
|
438
|
+
spec: './openapi.json',
|
|
439
|
+
output: './src/api.ts',
|
|
440
|
+
adaptor: 'axios',
|
|
441
|
+
// Keep generated paths relative so the instance owns the origin.
|
|
442
|
+
baseURL: '',
|
|
443
|
+
importClientSource: "import { apiClient as axios } from './lib/api-client'",
|
|
444
|
+
};
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
If you just want the axios package default, a bare import works too:
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
apicodegen ./openapi.json -a axios \
|
|
451
|
+
--importClientSource "import axios from 'axios'" \
|
|
452
|
+
-o ./src/api.ts
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
The CLI otherwise uses the spec's `servers[0].url` as the base. Pass
|
|
456
|
+
`--baseURL ""` (or `baseURL: ''` in a config file) to keep paths relative and
|
|
457
|
+
let the instance own the origin; an absolute server URL or explicit base
|
|
458
|
+
overrides the instance `baseURL`.
|
|
459
|
+
|
|
460
|
+
The imported value must satisfy the adaptor's contract:
|
|
461
|
+
|
|
462
|
+
- **axios**: generic and callable as
|
|
463
|
+
`<T>(url, config) => Promise<{ data: T; status: number }>`. The generated
|
|
464
|
+
`config` contains `method`, `headers`, `data` (request body), `signal` and
|
|
465
|
+
`timeout`; query parameters are already encoded into the URL. With
|
|
466
|
+
`errorMode: 'result'`, rejected errors must carry
|
|
467
|
+
`response: { status: number; data: unknown }`.
|
|
468
|
+
- **fetch**: a `fetch`-compatible function (`(input, init) => Promise<Response>`).
|
|
469
|
+
To inject a wrapper, alias it to `fetch` (for example
|
|
470
|
+
`import { myFetch as fetch } from './fetch'`).
|
|
471
|
+
|
|
472
|
+
Limitations:
|
|
473
|
+
|
|
474
|
+
- **The identifier is fixed.** Your import has to use `as axios` or `as fetch`;
|
|
475
|
+
the generated call site cannot be renamed.
|
|
476
|
+
- **Only the axios and fetch shapes are supported.** Clients such as `ky` or
|
|
477
|
+
`ofetch` need a thin wrapper matching one of the contracts above.
|
|
478
|
+
- **`--adaptor axios` without `importClientSource` produces code that references
|
|
479
|
+
an undefined `axios`** and will not compile. This is not caught at generation
|
|
480
|
+
time, so check the output or run your own `tsc --noEmit`.
|
|
481
|
+
|
|
208
482
|
---
|
|
209
483
|
|
|
210
484
|
## π Generated Code
|
|
@@ -280,9 +554,9 @@ export type Pet = {
|
|
|
280
554
|
| `object` | β
| Complex nested objects |
|
|
281
555
|
| `array` | β
| Nested and multi-dimensional |
|
|
282
556
|
| `enum` | β
| Auto-generated TypeScript enums |
|
|
283
|
-
| `oneOf` / `anyOf` | β
| Union types with deduplication |
|
|
557
|
+
| `oneOf` / `anyOf` | β
| Union types with deduplication; `discriminator.mapping` narrows `oneOf` members |
|
|
284
558
|
| `allOf` | β
| Intersection types |
|
|
285
|
-
| `$ref` | β
|
|
|
559
|
+
| `$ref` | β
| Local, cross-file and remote URL references; circular refs supported |
|
|
286
560
|
| `binary` / `blob` / `file` | β
| File upload types |
|
|
287
561
|
|
|
288
562
|
### Parameter Locations
|
|
@@ -292,9 +566,13 @@ export type Pet = {
|
|
|
292
566
|
| `path` | β
| `/users/{id}` |
|
|
293
567
|
| `query` | β
| `?page=1&limit=10` |
|
|
294
568
|
| `header` | β
| `X-API-Key: xxx` |
|
|
295
|
-
| `cookie` | β
| `
|
|
569
|
+
| `cookie` | β
| Sent as a `Cookie` header |
|
|
296
570
|
| `body` | β
| JSON and FormData |
|
|
297
571
|
|
|
572
|
+
Query arrays support `form`, `spaceDelimited`, and `pipeDelimited` with
|
|
573
|
+
`explode`. `deepObject` parameters serialize nested objects to
|
|
574
|
+
`filter[a]=1&filter[b][c]=2` at any depth.
|
|
575
|
+
|
|
298
576
|
### Request Body Formats
|
|
299
577
|
|
|
300
578
|
| Content-Type | Status |
|
|
@@ -305,13 +583,18 @@ export type Pet = {
|
|
|
305
583
|
| `text/plain` | β
|
|
|
306
584
|
| `image/*` | β
|
|
|
307
585
|
|
|
586
|
+
Multipart bodies always use `FormData` when the schema has only text parts
|
|
587
|
+
(string, number, boolean, arrays of those), not just for file uploads.
|
|
588
|
+
URL-encoded object bodies use `URLSearchParams`; arrays are sent as repeated
|
|
589
|
+
keys and nested objects/arrays are JSON-stringified.
|
|
590
|
+
|
|
308
591
|
### OpenAPI Versions
|
|
309
592
|
|
|
310
|
-
| Version | Status |
|
|
311
|
-
|
|
312
|
-
| OpenAPI 2.0 (Swagger) | β
|
|
|
313
|
-
| OpenAPI 3.0 | β
|
|
|
314
|
-
| OpenAPI 3.1 |
|
|
593
|
+
| Version | Status | Notes |
|
|
594
|
+
|---------|--------|-------|
|
|
595
|
+
| OpenAPI 2.0 (Swagger) | β
| |
|
|
596
|
+
| OpenAPI 3.0 | β
| |
|
|
597
|
+
| OpenAPI 3.1 | β οΈ | `type` arrays, `const`, and `additionalProperties` supported; webhooks are not modelled |
|
|
315
598
|
|
|
316
599
|
---
|
|
317
600
|
|
|
@@ -365,9 +648,11 @@ npx @moccona/apicodegen <url> -o ./src/api.ts
|
|
|
365
648
|
- Ensure `typescript` is installed: `npm install -D typescript`
|
|
366
649
|
- Run `tsc --noEmit` to see specific errors
|
|
367
650
|
- Verify your `tsconfig.json` is properly configured
|
|
651
|
+
- `Cannot find name 'axios'` means you used `--adaptor axios` without
|
|
652
|
+
`importClientSource`; see [Bring Your Own HTTP Client](#bring-your-own-http-client)
|
|
368
653
|
|
|
369
654
|
**Vite plugin not generating files**
|
|
370
|
-
- Ensure Node.js
|
|
655
|
+
- Ensure Node.js 22.18+ is installed
|
|
371
656
|
- Check that all required options (`name`, `output`) are provided
|
|
372
657
|
- Set `verbose: true` in plugin options
|
|
373
658
|
|
|
@@ -380,7 +665,7 @@ npx @moccona/apicodegen <url> -o ./src/api.ts
|
|
|
380
665
|
|
|
381
666
|
- π [CHANGELOG](CHANGELOG.md) - Recent updates
|
|
382
667
|
- π [GitHub Issues](https://github.com/freemode1614/api-codegen/issues) - Report bugs
|
|
383
|
-
- π [
|
|
668
|
+
- π [ROADMAP.md](ROADMAP.md) - Future plans
|
|
384
669
|
|
|
385
670
|
---
|
|
386
671
|
|
|
@@ -432,12 +717,10 @@ src/
|
|
|
432
717
|
|
|
433
718
|
## πΊοΈ Roadmap
|
|
434
719
|
|
|
435
|
-
See [
|
|
720
|
+
See [ROADMAP.md](ROADMAP.md) for the detailed, versioned plan:
|
|
436
721
|
|
|
437
|
-
- **
|
|
438
|
-
- **
|
|
439
|
-
- **v0.3.0** - VSCode LSP, GitHub Action, mock server
|
|
440
|
-
- **v0.4.0+** - Web UI, GraphQL support
|
|
722
|
+
- **v1.0.0** - Stable contract, auto baseURL, YAML, OpenAPI 3.1 types, auth, error modes, `--check`, multi-file output, request/response type split, Node 22.18
|
|
723
|
+
- **v1.1.0** - Ecosystem parity: Zod, MSW, framework hooks, plugin API, path-prefix splitting
|
|
441
724
|
|
|
442
725
|
---
|
|
443
726
|
|