@kubb/adapter-oas 5.18.5 → 5.18.7
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/dist/index.cjs +64 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +69 -74
- package/dist/index.js.map +1 -1
- package/docs/options.md +68 -24
- package/docs/overview.md +3 -3
- package/package.json +3 -3
package/docs/options.md
CHANGED
|
@@ -13,15 +13,15 @@ Pass these options to `adapterOas()`. All of them are optional.
|
|
|
13
13
|
| [`enums`](#enums) | Where inline enums live. |
|
|
14
14
|
| [`dateType`](#datetype) | How `date-time`, `date`, and `time` schemas are represented. |
|
|
15
15
|
| [`integerType`](#integertype) | How `int64` and `uint64` integers map to TypeScript. |
|
|
16
|
-
| [`unknownType`](#unknowntype) | Type for
|
|
17
|
-
| [`emptySchemaType`](#emptyschematype) | Type for
|
|
16
|
+
| [`unknownType`](#unknowntype) | Type for open map values and parameters without a schema. |
|
|
17
|
+
| [`emptySchemaType`](#emptyschematype) | Type for schemas with no type to infer. |
|
|
18
18
|
| [`enumSuffix`](#enumsuffix) | Suffix for derived enum names. |
|
|
19
19
|
|
|
20
20
|
## Option details
|
|
21
21
|
|
|
22
22
|
### validate
|
|
23
23
|
|
|
24
|
-
Validates the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is reported as a [`KUBB_INVALID_SPEC`](https://kubb.dev/docs/5.x/reference/diagnostics#kubb-invalid-spec) warning, and generation continues. Set it to `false` to skip the check, which makes generation faster on a large spec. Run [`kubb validate`](https://kubb.dev/docs/5.x/reference/commands/validate) to list every error. An OpenAPI 3.2 document is not validated yet, because `@readme/openapi-parser` does not support 3.2
|
|
24
|
+
Validates the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is reported as a [`KUBB_INVALID_SPEC`](https://kubb.dev/docs/5.x/reference/diagnostics#kubb-invalid-spec) warning, and generation continues. Set it to `false` to skip the check, which makes generation faster on a large spec. Run [`kubb validate`](https://kubb.dev/docs/5.x/reference/commands/validate) to list every error. An OpenAPI 3.2 document is not validated yet, because `@readme/openapi-parser` does not support 3.2. Kubb reports one warning that says so.
|
|
25
25
|
|
|
26
26
|
| | |
|
|
27
27
|
| -------- | --------- |
|
|
@@ -40,7 +40,7 @@ Media type to keep when an operation declares several, for both request bodies a
|
|
|
40
40
|
|
|
41
41
|
### server
|
|
42
42
|
|
|
43
|
-
Selects which entry in the spec's `servers` array Kubb resolves into the document `baseURL`, filling in any `{variable}` placeholders. `server.index` points at one of the spec's servers, usually `0` for the primary one. `server.variables` supplies placeholder values, falling back to each variable's `default` from the spec.
|
|
43
|
+
Selects which entry in the spec's `servers` array Kubb resolves into the document `baseURL`, filling in any `{variable}` placeholders. `server.index` points at one of the spec's servers, usually `0` for the primary one. `server.variables` supplies placeholder values, falling back to each variable's `default` from the spec. When `server` or `server.index` is omitted, `baseURL` resolves to `null`.
|
|
44
44
|
|
|
45
45
|
| | |
|
|
46
46
|
| -------- | -------------------------------------------------------- |
|
|
@@ -64,11 +64,11 @@ How `discriminator` fields on `oneOf`/`anyOf` schemas are interpreted.
|
|
|
64
64
|
::field-group
|
|
65
65
|
|
|
66
66
|
:::field{name="'preserve'"}
|
|
67
|
-
Keeps child schemas exactly as written
|
|
67
|
+
Keeps child schemas exactly as written. The parent union still narrows each branch by its discriminator value.
|
|
68
68
|
:::
|
|
69
69
|
|
|
70
70
|
:::field{name="'propagate'"}
|
|
71
|
-
|
|
71
|
+
Also writes the discriminator property with its literal value into each child schema, so `Cat` and `Dog` are narrowed when used on their own.
|
|
72
72
|
:::
|
|
73
73
|
|
|
74
74
|
::
|
|
@@ -80,8 +80,6 @@ openapi: 3.0.3
|
|
|
80
80
|
components:
|
|
81
81
|
schemas:
|
|
82
82
|
Animal:
|
|
83
|
-
required: [type]
|
|
84
|
-
type: object
|
|
85
83
|
oneOf:
|
|
86
84
|
- $ref: '#/components/schemas/Cat'
|
|
87
85
|
- $ref: '#/components/schemas/Dog'
|
|
@@ -103,15 +101,39 @@ components:
|
|
|
103
101
|
```
|
|
104
102
|
|
|
105
103
|
```typescript ['preserve' (default)]
|
|
106
|
-
export type Cat = {
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
export type Cat = {
|
|
105
|
+
type?: string;
|
|
106
|
+
indoor?: boolean;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type Dog = {
|
|
110
|
+
type?: string;
|
|
111
|
+
name?: string;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type Animal = Cat & {
|
|
115
|
+
type: 'cat';
|
|
116
|
+
} | Dog & {
|
|
117
|
+
type: 'dog';
|
|
118
|
+
};
|
|
109
119
|
```
|
|
110
120
|
|
|
111
121
|
```typescript ['propagate']
|
|
112
|
-
export type Cat = {
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
export type Cat = {
|
|
123
|
+
type: 'cat';
|
|
124
|
+
indoor?: boolean;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type Dog = {
|
|
128
|
+
type: 'dog';
|
|
129
|
+
name?: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type Animal = Cat & {
|
|
133
|
+
type: 'cat';
|
|
134
|
+
} | Dog & {
|
|
135
|
+
type: 'dog';
|
|
136
|
+
};
|
|
115
137
|
```
|
|
116
138
|
|
|
117
139
|
::
|
|
@@ -133,22 +155,44 @@ Keeps each enum on the property that declares it.
|
|
|
133
155
|
:::
|
|
134
156
|
|
|
135
157
|
:::field{name="'root'"}
|
|
136
|
-
Lifts every inline enum to a
|
|
158
|
+
Lifts every inline enum to a top-level schema named after its context (for example `PetStatusEnum`) and references it wherever it appears.
|
|
137
159
|
:::
|
|
138
160
|
|
|
139
161
|
::
|
|
140
162
|
|
|
141
|
-
For an enum with values `active` and `inactive` on `Pet.status
|
|
163
|
+
The names are the same in both modes. With `'root'`, the enum is a schema of its own, so a plugin that writes one file per schema gives it its own file. For an enum with values `active` and `inactive` on `Pet.status`, `@kubb/plugin-ts` writes:
|
|
142
164
|
|
|
143
165
|
::code-group
|
|
144
166
|
|
|
145
167
|
```typescript ['inline' (default)]
|
|
146
|
-
|
|
168
|
+
// types/Pet.ts
|
|
169
|
+
export const petStatusEnum = {
|
|
170
|
+
active: 'active',
|
|
171
|
+
inactive: 'inactive',
|
|
172
|
+
} as const;
|
|
173
|
+
|
|
174
|
+
export type PetStatusEnumKey = (typeof petStatusEnum)[keyof typeof petStatusEnum];
|
|
175
|
+
|
|
176
|
+
export type Pet = {
|
|
177
|
+
status?: PetStatusEnumKey;
|
|
178
|
+
};
|
|
147
179
|
```
|
|
148
180
|
|
|
149
181
|
```typescript ['root']
|
|
150
|
-
|
|
151
|
-
export
|
|
182
|
+
// types/PetStatusEnum.ts
|
|
183
|
+
export const petStatusEnum = {
|
|
184
|
+
active: 'active',
|
|
185
|
+
inactive: 'inactive',
|
|
186
|
+
} as const;
|
|
187
|
+
|
|
188
|
+
export type PetStatusEnumKey = (typeof petStatusEnum)[keyof typeof petStatusEnum];
|
|
189
|
+
|
|
190
|
+
// types/Pet.ts
|
|
191
|
+
import type { PetStatusEnumKey } from './PetStatusEnum'
|
|
192
|
+
|
|
193
|
+
export type Pet = {
|
|
194
|
+
status?: PetStatusEnumKey;
|
|
195
|
+
};
|
|
152
196
|
```
|
|
153
197
|
|
|
154
198
|
::
|
|
@@ -191,7 +235,7 @@ Represents date and time values as JavaScript `Date` objects. JSON values need p
|
|
|
191
235
|
|
|
192
236
|
The string variants all emit `string` at the TypeScript type level. Schema plugins such as `@kubb/plugin-zod` validate the offset or local format.
|
|
193
237
|
|
|
194
|
-
Pass an object to set `dateTime`, `date`, and `time` independently. A key
|
|
238
|
+
Pass an object to set `dateTime`, `date`, and `time` independently. A key that is left out defaults to `'string'`, regardless of the other keys.
|
|
195
239
|
|
|
196
240
|
```ts
|
|
197
241
|
adapterOas({
|
|
@@ -216,7 +260,7 @@ How a schema with `format: int64` or `format: uint64` maps to TypeScript. Other
|
|
|
216
260
|
::field-group
|
|
217
261
|
|
|
218
262
|
:::field{name="'bigint'"}
|
|
219
|
-
Represents 64-bit IDs exactly, but `JSON.stringify` and `JSON.parse` cannot round-trip it. Use it only when
|
|
263
|
+
Represents 64-bit IDs exactly, but `JSON.stringify` and `JSON.parse` cannot round-trip it. Use it only when the application handles bigint serialization itself.
|
|
220
264
|
:::
|
|
221
265
|
|
|
222
266
|
:::field{name="'number'"}
|
|
@@ -229,7 +273,7 @@ A schema with `type: string` stays a `string` whatever its `format`, so the [Pro
|
|
|
229
273
|
|
|
230
274
|
### unknownType
|
|
231
275
|
|
|
232
|
-
AST type used
|
|
276
|
+
AST type used where the spec allows any value but gives no schema for it: the values of `additionalProperties: {}`, a `patternProperties` entry set to `true` or `{}`, the extra items of an open `prefixItems` tuple, and a parameter without a `schema`. `additionalProperties: true` is not affected, and `@kubb/plugin-ts` always types its values as `unknown`.
|
|
233
277
|
|
|
234
278
|
| | |
|
|
235
279
|
| -------- | ------------------------------ |
|
|
@@ -255,7 +299,7 @@ Represents a value callers should not use. Choose it when matching a legacy API
|
|
|
255
299
|
|
|
256
300
|
### emptySchemaType
|
|
257
301
|
|
|
258
|
-
AST type used for empty
|
|
302
|
+
AST type used for a schema with nothing to infer a type from: an empty schema (`{}`), a schema without a `type` such as one that holds only a `description`, and a response without a schema. `emptySchemaType` takes the same values as [`unknownType`](#unknowntype) and follows it when unset.
|
|
259
303
|
|
|
260
304
|
| | |
|
|
261
305
|
| -------- | -------------------------------------- |
|
|
@@ -268,7 +312,7 @@ AST type used for empty schemas (`{}`). It takes the same values as [`unknownTyp
|
|
|
268
312
|
|
|
269
313
|
### enumSuffix
|
|
270
314
|
|
|
271
|
-
Suffix for the names Kubb gives inline enums: schema name, property name, and suffix, in PascalCase. The `status` enum on `Pet` becomes `PetStatusEnum`, or `PetStatusType` with `enumSuffix: 'type'`.
|
|
315
|
+
Suffix for the names Kubb gives inline enums: schema name, property name, and suffix, in PascalCase. The `status` enum on `Pet` becomes `PetStatusEnum`, or `PetStatusType` with `enumSuffix: 'type'`. Plugins derive their own names from it, such as `petStatusEnum` and `PetStatusEnumKey` in `@kubb/plugin-ts`.
|
|
272
316
|
|
|
273
317
|
| | |
|
|
274
318
|
| -------- | -------- |
|
package/docs/overview.md
CHANGED
|
@@ -13,9 +13,9 @@ Kubb uses `adapterOas()` by default, so no setup is needed. Set `adapter` in `de
|
|
|
13
13
|
- `validate` checks the spec before parsing and reports each problem as a warning. Turn it off to speed up a large spec. Run `kubb validate` to list every error.
|
|
14
14
|
- `dateType` sets how `date-time`, `date`, and `time` schemas are typed. Choose ISO strings (the default), `date-time` strings with or without a timezone offset, or JavaScript `Date` objects. Pass an object to set each format on its own.
|
|
15
15
|
- `integerType` sets how `int64` and `uint64` schemas are typed. The default `'bigint'` is exact for 64-bit IDs but does not survive `JSON.stringify`. Choose `'number'` for most JSON APIs.
|
|
16
|
-
- `unknownType`
|
|
17
|
-
- `discriminator: 'propagate'` writes the discriminator's literal value into each child schema, so
|
|
18
|
-
- `enums: 'root'` lifts inline enums to
|
|
16
|
+
- `unknownType` sets the type for open map values and parameters without a schema. `emptySchemaType` sets the type for empty schemas (`{}`) and schemas without a `type`.
|
|
17
|
+
- `discriminator: 'propagate'` writes the discriminator's literal value into each child schema, so a child is narrowed when used on its own.
|
|
18
|
+
- `enums: 'root'` lifts inline enums to top-level schemas, named with `enumSuffix` (`PetStatusEnum`).
|
|
19
19
|
- `server` picks the entry in the spec's `servers` array that becomes the base URL and fills in its variables. It does not change where a generated client sends requests. Use the client plugin's own `baseURL` for that.
|
|
20
20
|
- `contentType` picks one media type when an operation declares several. Without it, Kubb keeps every media type the operation declares.
|
|
21
21
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/adapter-oas",
|
|
3
|
-
"version": "5.18.
|
|
3
|
+
"version": "5.18.7",
|
|
4
4
|
"description": "OpenAPI and Swagger adapter for Kubb. Parses and validates OAS 2.0/3.x specifications into a @kubb/ast RootNode for downstream code generation plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"registry": "https://registry.npmjs.org/"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "^5.18.
|
|
70
|
-
"@kubb/kit": "5.18.
|
|
69
|
+
"@kubb/core": "^5.18.7",
|
|
70
|
+
"@kubb/kit": "5.18.7",
|
|
71
71
|
"@readme/openapi-parser": "^10.0.0",
|
|
72
72
|
"@scalar/openapi-upgrader": "^0.4.7",
|
|
73
73
|
"api-ref-bundler": "0.5.1",
|