@kubb/plugin-axios 5.5.10 → 5.5.12
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 +2 -2
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/docs/guides/authentication.md +77 -0
- package/docs/guides/base-url.md +63 -0
- package/docs/guides/calling-operations.md +147 -0
- package/docs/guides/error-handling.md +124 -0
- package/docs/guides/interceptors.md +82 -0
- package/docs/guides/serialization.md +120 -0
- package/docs/guides/server-sent-events.md +99 -0
- package/docs/guides/transport.md +50 -0
- package/docs/options.md +173 -0
- package/docs/overview.md +40 -0
- package/kubb-extension.json +9 -2
- package/package.json +7 -7
- package/src/plugin.ts +3 -2
- package/OVERVIEW.md +0 -19
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Server-sent events
|
|
2
|
+
|
|
3
|
+
Operations returning `text/event-stream` produce a typed stream rather than a `RequestResult`. The client switches to the axios fetch adapter for these calls unless you set `adapter` yourself, because the default XHR adapter buffers the whole body.
|
|
4
|
+
|
|
5
|
+
## Consume a stream
|
|
6
|
+
|
|
7
|
+
Read the `EventStreamResult.stream` with `for await`:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { streamEvents } from './gen/clients/streamEvents'
|
|
11
|
+
|
|
12
|
+
const { stream } = await streamEvents({})
|
|
13
|
+
|
|
14
|
+
for await (const event of stream) {
|
|
15
|
+
console.info(event.data)
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`data` is typed from the operation's response schema. Each event also carries the optional SSE
|
|
20
|
+
fields, so you can branch on the event name or read the id:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
type ServerSentEvent<TData> = {
|
|
24
|
+
data: TData
|
|
25
|
+
event?: string
|
|
26
|
+
id?: string
|
|
27
|
+
retry?: number
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The runtime parses each event's `data` as JSON when it is valid and keeps it as the raw string
|
|
32
|
+
otherwise.
|
|
33
|
+
|
|
34
|
+
## Stop early
|
|
35
|
+
|
|
36
|
+
Break out of the loop to stop reading. The underlying reader is canceled when the iterator
|
|
37
|
+
finishes, so an early `break` releases the stream:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const { stream } = await streamEvents({})
|
|
41
|
+
|
|
42
|
+
for await (const event of stream) {
|
|
43
|
+
if (event.event === 'done') break
|
|
44
|
+
render(event.data)
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To stop a stream from outside the loop, pass an `AbortSignal` and abort it. Aborting ends the
|
|
49
|
+
request and the iteration:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const controller = new AbortController()
|
|
53
|
+
const { stream } = await streamEvents({ signal: controller.signal })
|
|
54
|
+
|
|
55
|
+
// elsewhere, for example on component unmount
|
|
56
|
+
controller.abort()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Read the response
|
|
60
|
+
|
|
61
|
+
Read status and headers from the native `response` before iterating:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const { stream, response } = await streamEvents({})
|
|
65
|
+
|
|
66
|
+
console.info(response.status) // 200
|
|
67
|
+
console.info(response.headers.get('x-stream-id'))
|
|
68
|
+
|
|
69
|
+
for await (const event of stream) {
|
|
70
|
+
handle(event.data)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Handle errors
|
|
75
|
+
|
|
76
|
+
Catch non-2xx responses around the call and iteration, and rethrow other errors such as connection failures:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { ResponseError } from './gen/.kubb/client'
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const { stream } = await streamEvents({})
|
|
83
|
+
for await (const event of stream) {
|
|
84
|
+
handle(event.data)
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (!ResponseError.is(error)) throw error
|
|
88
|
+
console.error('stream rejected', error.status)
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> [!NOTE]
|
|
93
|
+
> A drop mid-stream ends the `for await` loop. Track the last event's `id` if you need to reconnect
|
|
94
|
+
> from where the stream stopped.
|
|
95
|
+
|
|
96
|
+
## See also
|
|
97
|
+
|
|
98
|
+
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/calling-operations)
|
|
99
|
+
- [Handle errors](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/error-handling)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Use a custom transport
|
|
2
|
+
|
|
3
|
+
Set a transport at runtime to replace the network send. The client still builds URLs, serializes parameters, resolves authentication, and handles results.
|
|
4
|
+
|
|
5
|
+
The transport is an `AxiosInstance`. The default is `axios.create()`, and you can replace it with your own pre-configured instance. Use interceptors for request headers or response logging.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
type ClientConfig = {
|
|
9
|
+
// ...
|
|
10
|
+
transport?: AxiosInstance
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Kubb forwards the resolved URL, query, body, and authentication to the instance.
|
|
15
|
+
|
|
16
|
+
## Pass a pre-configured instance
|
|
17
|
+
|
|
18
|
+
Give the client an instance with a timeout, default headers, and a logging interceptor:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import axios from 'axios'
|
|
22
|
+
import { client } from './gen/.kubb/client'
|
|
23
|
+
|
|
24
|
+
const instance = axios.create({
|
|
25
|
+
timeout: 10_000,
|
|
26
|
+
headers: { 'X-Client': 'kubb' },
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
instance.interceptors.response.use((response) => {
|
|
30
|
+
console.info(`${response.config.method?.toUpperCase()} ${response.config.url} -> ${response.status}`)
|
|
31
|
+
return response
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
client.setConfig({ transport: instance })
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Every generated function now sends through your instance, so its timeout, headers, and interceptors apply to each call. Interceptors registered through `client.interceptors` move to the new instance and keep their IDs for `eject` and `update`.
|
|
38
|
+
|
|
39
|
+
> [!NOTE]
|
|
40
|
+
> Kubb sets `transformRequest`, `paramsSerializer`, and `validateStatus` on each request for its own serialization and `throwOnError` handling, so leave those fields alone. Set timeouts, retries, and interceptors on the instance. For one call, pass `options`, such as `{ timeout }` or `{ onUploadProgress }`, instead of building a new instance.
|
|
41
|
+
|
|
42
|
+
## Where to set it
|
|
43
|
+
|
|
44
|
+
Use `client.setConfig({ transport })` for shared configuration, `createClient({ transport })` for an isolated instance, or pass `transport` on an operation to override it for one call.
|
|
45
|
+
|
|
46
|
+
## See also
|
|
47
|
+
|
|
48
|
+
- [Add interceptors](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/interceptors)
|
|
49
|
+
- [Set the base URL](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/base-url)
|
|
50
|
+
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/calling-operations)
|
package/docs/options.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Options
|
|
2
|
+
|
|
3
|
+
Pass these options to `pluginAxios()`. Shared options link to [Shared plugin options](https://kubb.dev/docs/5.x/reference/plugin-options).
|
|
4
|
+
|
|
5
|
+
## Options overview
|
|
6
|
+
|
|
7
|
+
| Option | Purpose | Default |
|
|
8
|
+
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------ |
|
|
9
|
+
| [`output`](https://kubb.dev/docs/5.x/reference/plugin-options#output) | Where files are written: `path`, `mode`, `barrel`, `banner`, `footer`. | `{ path: 'clients', barrel: { type: 'named' } }` |
|
|
10
|
+
| [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path: `type`, `name`. | None |
|
|
11
|
+
| [`baseURL`](#baseurl) | Base URL prepended to every request. | None |
|
|
12
|
+
| [`throwOnErrorDefault`](#throwonerrordefault) | Default error behavior and return type for generated operations. | `true` |
|
|
13
|
+
| [`validator`](#validator) | Validate request and response bodies with Zod. | `false` |
|
|
14
|
+
| [`sdk`](#sdk) | Emit a class-based SDK instead of standalone functions. | None |
|
|
15
|
+
| [`returnType`](#returntype) | Shape of the value a generated call resolves to. | `'full'` |
|
|
16
|
+
| [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
|
|
17
|
+
| [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
|
|
18
|
+
| [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
|
|
19
|
+
| [`resolver`](#resolver) | Customize generated names and file paths. | `resolverClient` |
|
|
20
|
+
| [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]`, run after the built-in client macros |
|
|
21
|
+
|
|
22
|
+
## Option details
|
|
23
|
+
|
|
24
|
+
### baseURL
|
|
25
|
+
|
|
26
|
+
Base URL prepended to every request. When omitted, each request uses the operation's relative path from the spec, with no server-URL fallback. A value with a `${...}` interpolation is emitted as a template literal, so `baseURL: '${process.env.API_URL}'` reads the environment variable at runtime.
|
|
27
|
+
|
|
28
|
+
| | |
|
|
29
|
+
| -------- | -------- |
|
|
30
|
+
| Type | `string` |
|
|
31
|
+
| Required | `false` |
|
|
32
|
+
|
|
33
|
+
### throwOnErrorDefault
|
|
34
|
+
|
|
35
|
+
Set `throwOnErrorDefault: false` to return documented error responses as values by default. It sets the fallback on each generated request and the default `ThrowOnError` type parameter on functions and SDK methods. It applies to the whole plugin, so `override` cannot set it. A call that passes `throwOnError` still wins. With `throwOnError: true`, a non-2xx response throws and the return type narrows to successful responses. Query hooks always pass `throwOnError: true`.
|
|
36
|
+
|
|
37
|
+
| | |
|
|
38
|
+
| -------- | --------- |
|
|
39
|
+
| Type | `boolean` |
|
|
40
|
+
| Required | `false` |
|
|
41
|
+
| Default | `true` |
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// with pluginAxios({ throwOnErrorDefault: false })
|
|
45
|
+
const result = await getPetById({ path: { petId: 1 } })
|
|
46
|
+
if (result.status !== 200) console.error(result.status, result.error)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### validator
|
|
50
|
+
|
|
51
|
+
Validates request and response bodies with schemas from `@kubb/plugin-zod`, so add `pluginZod()` too. An invalid body makes the generated function throw a `ParseError`.
|
|
52
|
+
|
|
53
|
+
| | |
|
|
54
|
+
| -------- | --------------------------------------------------------- |
|
|
55
|
+
| Type | `false \| 'zod' \| { request?: 'zod'; response?: 'zod' }` |
|
|
56
|
+
| Required | `false` |
|
|
57
|
+
| Default | `false` |
|
|
58
|
+
|
|
59
|
+
::field-group
|
|
60
|
+
|
|
61
|
+
:::field{name="false"}
|
|
62
|
+
Default value. Skips validation and casts the response to the generated type.
|
|
63
|
+
:::
|
|
64
|
+
|
|
65
|
+
:::field{name="'zod'"}
|
|
66
|
+
Validates the success response body and, when a non-2xx call does not throw, the error body.
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
:::field{name="{ request?: 'zod', response?: 'zod' }"}
|
|
70
|
+
Enables validation separately for requests and responses.
|
|
71
|
+
:::
|
|
72
|
+
|
|
73
|
+
::
|
|
74
|
+
|
|
75
|
+
```typescript [kubb.config.ts]
|
|
76
|
+
import { defineConfig } from 'kubb/config'
|
|
77
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
78
|
+
import { pluginZod } from '@kubb/plugin-zod'
|
|
79
|
+
import { pluginAxios } from '@kubb/plugin-axios'
|
|
80
|
+
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
input: './petStore.yaml',
|
|
83
|
+
output: { path: './src/gen' },
|
|
84
|
+
plugins: [
|
|
85
|
+
pluginTs(),
|
|
86
|
+
pluginZod(),
|
|
87
|
+
pluginAxios({ validator: { request: 'zod', response: 'zod' } }),
|
|
88
|
+
],
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### sdk
|
|
93
|
+
|
|
94
|
+
Generates a class-based SDK. Each instance takes its own client config, so environments can use separate clients. Leave `sdk` unset to keep the standalone functions that query plugins call.
|
|
95
|
+
|
|
96
|
+
| | |
|
|
97
|
+
| -------- | ------------------------------------------- |
|
|
98
|
+
| Type | `{ mode?: 'tag' \| 'flat'; name?: string }` |
|
|
99
|
+
| Required | `false` |
|
|
100
|
+
|
|
101
|
+
::field-group
|
|
102
|
+
|
|
103
|
+
:::field{name="'tag'"}
|
|
104
|
+
Default value for `sdk.mode`. Generates one class per tag, such as `PetClient`. Set `sdk.name` to also get a root class that shares one config, used as `new PetStore(config).pet.getPetById(...)`.
|
|
105
|
+
:::
|
|
106
|
+
|
|
107
|
+
:::field{name="'flat'"}
|
|
108
|
+
Generates one class named by `sdk.name`, with every operation as a method. Supports single-file output.
|
|
109
|
+
:::
|
|
110
|
+
|
|
111
|
+
::
|
|
112
|
+
|
|
113
|
+
`mode: 'tag'` needs one file per tag, so it throws [`KUBB_INVALID_PLUGIN_OPTIONS`](https://kubb.dev/docs/5.x/reference/diagnostics#kubb-invalid-plugin-options) with single-file output. Use `mode: 'flat'` for a single file.
|
|
114
|
+
|
|
115
|
+
Methods take the same grouped options and return the same result as the standalone functions. See [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-axios/guides/calling-operations).
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const pet = new PetClient({ baseURL: 'https://petstore.swagger.io/v2' })
|
|
119
|
+
const { data } = await pet.getPetById({ path: { petId: 1 } })
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### returnType
|
|
123
|
+
|
|
124
|
+
Shape of the value a generated call resolves to.
|
|
125
|
+
|
|
126
|
+
| | |
|
|
127
|
+
| -------- | ------------------ |
|
|
128
|
+
| Type | `'full' \| 'data'` |
|
|
129
|
+
| Required | `false` |
|
|
130
|
+
| Default | `'full'` |
|
|
131
|
+
|
|
132
|
+
::field-group
|
|
133
|
+
|
|
134
|
+
:::field{name="'full'"}
|
|
135
|
+
Default value. Returns `{ status, data, error, contentType, request, response }`.
|
|
136
|
+
:::
|
|
137
|
+
|
|
138
|
+
:::field{name="'data'"}
|
|
139
|
+
Returns the success body when `throwOnError` is `true`. With `throwOnError: false`, returns the full result so callers can tell errors from successes.
|
|
140
|
+
:::
|
|
141
|
+
|
|
142
|
+
::
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
pluginAxios({ returnType: 'data' })
|
|
146
|
+
|
|
147
|
+
const pet = await getPetById({ path: { petId: 1 } }) // Pet, not { status, data, ... }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
It applies to the functions and the SDK. The query plugins and `@kubb/plugin-mcp` read it too, including a per-operation value set through [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override). To read headers such as `ETag` under `'data'`, pass `throwOnError: false` and read `result.response.headers`.
|
|
151
|
+
|
|
152
|
+
### resolver
|
|
153
|
+
|
|
154
|
+
Overrides generated file and symbol names. Omitted members keep `resolverClient`. The shared members (`name`, `file`, `imports`) and the `this` context are described under [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver).
|
|
155
|
+
|
|
156
|
+
| | |
|
|
157
|
+
| -------- | ------------------------------- |
|
|
158
|
+
| Type | `ResolverPatch<ResolverClient>` |
|
|
159
|
+
| Required | `false` |
|
|
160
|
+
|
|
161
|
+
```typescript [Partial override]
|
|
162
|
+
type ResolverClientPatch = {
|
|
163
|
+
name?(name: string): string
|
|
164
|
+
file?: {
|
|
165
|
+
baseName?(params: { name: string; extname: string }): string
|
|
166
|
+
path?(params: { baseName: string; output: Output }): string
|
|
167
|
+
}
|
|
168
|
+
imports?(options: ResolveImportsOptions): Array<ImportNode>
|
|
169
|
+
className?(name: string): string
|
|
170
|
+
groupName?(name: string): string // → 'PetClient'
|
|
171
|
+
propertyName?(name: string): string
|
|
172
|
+
}
|
|
173
|
+
```
|
package/docs/overview.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Axios
|
|
2
|
+
|
|
3
|
+
The Axios plugin turns each operation in your OpenAPI spec into a typed async function that sends the request with axios. Each function takes grouped `path`, `query`, `headers`, and `body` parameters and returns a result keyed by status code.
|
|
4
|
+
|
|
5
|
+
The query plugins (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, and `@kubb/plugin-swr`) and `@kubb/plugin-mcp` call these functions. The plugin also copies its runtime files (`client.ts`, `serializers.ts`, and `standardSchema.ts`) to `.kubb/` in the root output folder.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
- Add `@kubb/plugin-ts` for the operation types, or `@kubb/plugin-zod` with `inferred: true`.
|
|
10
|
+
- Add `@kubb/plugin-zod` when you set `validator`, and install `zod` v4. Without the plugin, `validator` does nothing.
|
|
11
|
+
- Install `axios` 1.20 or a later v1 release in the app that uses the generated code.
|
|
12
|
+
|
|
13
|
+
## Options worth knowing
|
|
14
|
+
|
|
15
|
+
- `baseURL` is prepended to every request. The spec's `servers` URL is not used, so without `baseURL` you set one at runtime with `client.setConfig({ baseURL })`.
|
|
16
|
+
- `validator: 'zod'` validates response bodies with the schemas from `@kubb/plugin-zod`. Use `{ request: 'zod', response: 'zod' }` to also validate request bodies.
|
|
17
|
+
- `throwOnErrorDefault: false` returns non-2xx responses as values instead of throwing. A single call can still pass `throwOnError`.
|
|
18
|
+
- `returnType: 'data'` makes a call resolve to the success body instead of the full result. With `throwOnError: false`, the call still returns the full result.
|
|
19
|
+
- `sdk` generates a class-based SDK, grouped by tag or flat, instead of standalone functions. The query plugins and `@kubb/plugin-mcp` need the standalone functions, so leave `sdk` unset when you use them.
|
|
20
|
+
|
|
21
|
+
See [Options](https://kubb.dev/extensions/kubb-labs/plugin-axios/options) for every option and its default.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
The config below generates an axios client that sends every request to the Petstore API.
|
|
26
|
+
|
|
27
|
+
```typescript [kubb.config.ts]
|
|
28
|
+
import { defineConfig } from 'kubb/config'
|
|
29
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
30
|
+
import { pluginAxios } from '@kubb/plugin-axios'
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
input: './petStore.yaml',
|
|
34
|
+
output: { path: './src/gen' },
|
|
35
|
+
plugins: [
|
|
36
|
+
pluginTs(),
|
|
37
|
+
pluginAxios({ baseURL: 'https://petstore.swagger.io/v2' }),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
```
|
package/kubb-extension.json
CHANGED
|
@@ -10,9 +10,16 @@
|
|
|
10
10
|
"light": "https://kubb.dev/feature/axios.svg"
|
|
11
11
|
},
|
|
12
12
|
"tags": ["api-client", "axios", "http-client", "codegen", "openapi", "validator"],
|
|
13
|
-
"docs": "https://kubb.dev/
|
|
13
|
+
"docs": "https://kubb.dev/extensions/kubb-labs/plugin-axios",
|
|
14
|
+
"maintainers": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Stijn Van Hulle",
|
|
17
|
+
"github": "stijnvanhulle"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"dependencies": ["plugin-ts"],
|
|
14
21
|
"compatibility": {
|
|
15
|
-
"kubb": ">=5.8.
|
|
22
|
+
"kubb": ">=5.8.3",
|
|
16
23
|
"node": ">=22"
|
|
17
24
|
},
|
|
18
25
|
"role": "client",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-axios",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.12",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"swagger",
|
|
14
14
|
"typescript"
|
|
15
15
|
],
|
|
16
|
-
"homepage": "https://kubb.dev/
|
|
16
|
+
"homepage": "https://kubb.dev/extensions/kubb-labs/plugin-axios",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"author": "stijnvanhulle",
|
|
19
19
|
"repository": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist",
|
|
41
41
|
"templates",
|
|
42
42
|
"kubb-extension.json",
|
|
43
|
-
"
|
|
43
|
+
"docs",
|
|
44
44
|
"!/**/**.test.**",
|
|
45
45
|
"!/**/__tests__/**",
|
|
46
46
|
"!/**/__snapshots__/**"
|
|
@@ -68,19 +68,19 @@
|
|
|
68
68
|
"registry": "https://registry.npmjs.org/"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@kubb/plugin-ts": "^5.0.
|
|
72
|
-
"@kubb/plugin-zod": "^5.4.
|
|
71
|
+
"@kubb/plugin-ts": "^5.0.10",
|
|
72
|
+
"@kubb/plugin-zod": "^5.4.8"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@internals/client": "0.0.0",
|
|
76
76
|
"@internals/shared": "0.0.0",
|
|
77
77
|
"axios": "^1.20.0",
|
|
78
|
-
"kubb": "^5.8.
|
|
78
|
+
"kubb": "^5.8.3",
|
|
79
79
|
"typescript": "^6.0.3"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"axios": "^1.20.0",
|
|
83
|
-
"kubb": "^5.8.
|
|
83
|
+
"kubb": "^5.8.3"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|
|
86
86
|
"axios": {
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
|
|
3
3
|
import { createGroupConfig } from '@internals/shared'
|
|
4
|
-
import { addGenerator,
|
|
4
|
+
import { addGenerator, defineExtension, injectFile, Resolver, setMacros, setResolver, useConfig } from 'kubb/kit'
|
|
5
5
|
import { compatibility } from '../kubb-extension.json'
|
|
6
6
|
import { version } from '../package.json'
|
|
7
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -38,7 +38,8 @@ export const pluginAxiosName = 'plugin-axios' satisfies PluginAxios['name']
|
|
|
38
38
|
* })
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export const pluginAxios =
|
|
41
|
+
export const pluginAxios = defineExtension<PluginAxios>({
|
|
42
|
+
kind: 'plugin',
|
|
42
43
|
meta: { name: pluginAxiosName, version, compatibility },
|
|
43
44
|
// Both are ordering hints, skipped when the plugin is not in the pipeline. `plugin-ts` supplies
|
|
44
45
|
// the operation types unless it is absent, in which case `pluginZod({ inferred: true })` does.
|
package/OVERVIEW.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Axios
|
|
2
|
-
|
|
3
|
-
Generates a type-safe HTTP client based on axios from your OpenAPI spec. Each operation becomes one async function with grouped `path`, `query`, `headers`, and `body` parameters and a result keyed by status code.
|
|
4
|
-
|
|
5
|
-
This plugin provides the client runtime. Query plugins such as `@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, `@kubb/plugin-swr`, and `@kubb/plugin-mcp` call the functions it generates.
|
|
6
|
-
|
|
7
|
-
## Setup
|
|
8
|
-
|
|
9
|
-
- Add `@kubb/plugin-ts` for the operation types. Without it, `@kubb/plugin-zod` with `inferred: true` supplies them.
|
|
10
|
-
- Add `@kubb/plugin-zod` when you set `validator`.
|
|
11
|
-
- Install axios v1 or higher in the app that uses the generated code.
|
|
12
|
-
|
|
13
|
-
## Options worth knowing
|
|
14
|
-
|
|
15
|
-
- `baseURL` is prepended to every request.
|
|
16
|
-
- `validator: 'zod'` validates request and response bodies with the schemas from `@kubb/plugin-zod`.
|
|
17
|
-
- `sdk` generates a class-based SDK, grouped by tag or flat, instead of standalone functions. Query plugins need the standalone functions, so leave `sdk` unset when you use them.
|
|
18
|
-
- `returnType: 'data'` makes a call resolve to the success body instead of the full result with status, data, and error.
|
|
19
|
-
- `throwOnErrorDefault: false` returns documented error responses as values instead of throwing. A single call can still pass `throwOnError`.
|