@kubb/adapter-oas 5.0.0-alpha.9 → 5.0.0-beta.2
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 +1299 -1242
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +522 -144
- package/dist/index.js +1290 -1236
- package/dist/index.js.map +1 -1
- package/package.json +32 -35
- package/src/adapter.ts +82 -78
- package/src/constants.ts +77 -69
- package/src/discriminator.ts +108 -0
- package/src/factory.ts +165 -0
- package/src/guards.ts +68 -0
- package/src/index.ts +17 -0
- package/src/parser.ts +565 -655
- package/src/refs.ts +59 -0
- package/src/resolvers.ts +544 -0
- package/src/types.ts +172 -59
- package/src/oas/Oas.ts +0 -623
- package/src/oas/resolveServerUrl.ts +0 -47
- package/src/oas/types.ts +0 -71
- package/src/oas/utils.ts +0 -402
- package/src/utils.ts +0 -168
package/dist/index.d.ts
CHANGED
|
@@ -1,124 +1,450 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import * as _kubb_core0 from "@kubb/core";
|
|
3
|
-
import { AdapterFactoryOptions } from "@kubb/core";
|
|
4
|
-
import { DiscriminatorObject, OASDocument,
|
|
5
|
-
import
|
|
6
|
-
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
7
|
-
import { Operation } from "oas/operation";
|
|
8
|
-
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import * as _$_kubb_core0 from "@kubb/core";
|
|
3
|
+
import { AdapterFactoryOptions, AdapterSource, ast } from "@kubb/core";
|
|
4
|
+
import { DiscriminatorObject as DiscriminatorObject$2, MediaTypeObject as MediaTypeObject$2, OASDocument, ResponseObject as ResponseObject$2, SchemaObject as SchemaObject$2 } from "oas/types";
|
|
5
|
+
import { Operation as Operation$1 } from "oas/operation";
|
|
9
6
|
|
|
10
|
-
//#region
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
//#region ../../node_modules/.pnpm/openapi-types@12.1.3/node_modules/openapi-types/dist/index.d.ts
|
|
8
|
+
declare namespace OpenAPIV3 {
|
|
9
|
+
interface Document<T extends {} = {}> {
|
|
10
|
+
openapi: string;
|
|
11
|
+
info: InfoObject;
|
|
12
|
+
servers?: ServerObject[];
|
|
13
|
+
paths: PathsObject<T>;
|
|
14
|
+
components?: ComponentsObject;
|
|
15
|
+
security?: SecurityRequirementObject[];
|
|
16
|
+
tags?: TagObject[];
|
|
17
|
+
externalDocs?: ExternalDocumentationObject;
|
|
18
|
+
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
19
|
+
'x-express-openapi-validation-strict'?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface InfoObject {
|
|
22
|
+
title: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
termsOfService?: string;
|
|
25
|
+
contact?: ContactObject;
|
|
26
|
+
license?: LicenseObject;
|
|
27
|
+
version: string;
|
|
28
|
+
}
|
|
29
|
+
interface ContactObject {
|
|
30
|
+
name?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
}
|
|
34
|
+
interface LicenseObject {
|
|
35
|
+
name: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ServerObject {
|
|
39
|
+
url: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
variables?: {
|
|
42
|
+
[variable: string]: ServerVariableObject;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface ServerVariableObject {
|
|
46
|
+
enum?: string[];
|
|
47
|
+
default: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
}
|
|
50
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
51
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
52
|
+
}
|
|
53
|
+
enum HttpMethods {
|
|
54
|
+
GET = "get",
|
|
55
|
+
PUT = "put",
|
|
56
|
+
POST = "post",
|
|
57
|
+
DELETE = "delete",
|
|
58
|
+
OPTIONS = "options",
|
|
59
|
+
HEAD = "head",
|
|
60
|
+
PATCH = "patch",
|
|
61
|
+
TRACE = "trace"
|
|
62
|
+
}
|
|
63
|
+
type PathItemObject<T extends {} = {}> = {
|
|
64
|
+
$ref?: string;
|
|
65
|
+
summary?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
servers?: ServerObject[];
|
|
68
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
69
|
+
} & { [method in HttpMethods]?: OperationObject<T> };
|
|
70
|
+
type OperationObject<T extends {} = {}> = {
|
|
71
|
+
tags?: string[];
|
|
72
|
+
summary?: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
externalDocs?: ExternalDocumentationObject;
|
|
75
|
+
operationId?: string;
|
|
76
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
77
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
78
|
+
responses: ResponsesObject;
|
|
79
|
+
callbacks?: {
|
|
80
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
81
|
+
};
|
|
82
|
+
deprecated?: boolean;
|
|
83
|
+
security?: SecurityRequirementObject[];
|
|
84
|
+
servers?: ServerObject[];
|
|
85
|
+
} & T;
|
|
86
|
+
interface ExternalDocumentationObject {
|
|
87
|
+
description?: string;
|
|
88
|
+
url: string;
|
|
89
|
+
}
|
|
90
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
91
|
+
name: string;
|
|
92
|
+
in: string;
|
|
93
|
+
}
|
|
94
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
95
|
+
interface ParameterBaseObject {
|
|
96
|
+
description?: string;
|
|
97
|
+
required?: boolean;
|
|
98
|
+
deprecated?: boolean;
|
|
99
|
+
allowEmptyValue?: boolean;
|
|
100
|
+
style?: string;
|
|
101
|
+
explode?: boolean;
|
|
102
|
+
allowReserved?: boolean;
|
|
103
|
+
schema?: ReferenceObject | SchemaObject;
|
|
104
|
+
example?: any;
|
|
105
|
+
examples?: {
|
|
106
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
107
|
+
};
|
|
108
|
+
content?: {
|
|
109
|
+
[media: string]: MediaTypeObject;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
113
|
+
type ArraySchemaObjectType = 'array';
|
|
114
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
115
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
116
|
+
type: ArraySchemaObjectType;
|
|
117
|
+
items: ReferenceObject | SchemaObject;
|
|
118
|
+
}
|
|
119
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
120
|
+
type?: NonArraySchemaObjectType;
|
|
121
|
+
}
|
|
122
|
+
interface BaseSchemaObject {
|
|
123
|
+
title?: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
format?: string;
|
|
126
|
+
default?: any;
|
|
127
|
+
multipleOf?: number;
|
|
128
|
+
maximum?: number;
|
|
129
|
+
exclusiveMaximum?: boolean;
|
|
130
|
+
minimum?: number;
|
|
131
|
+
exclusiveMinimum?: boolean;
|
|
132
|
+
maxLength?: number;
|
|
133
|
+
minLength?: number;
|
|
134
|
+
pattern?: string;
|
|
135
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
136
|
+
maxItems?: number;
|
|
137
|
+
minItems?: number;
|
|
138
|
+
uniqueItems?: boolean;
|
|
139
|
+
maxProperties?: number;
|
|
140
|
+
minProperties?: number;
|
|
141
|
+
required?: string[];
|
|
142
|
+
enum?: any[];
|
|
143
|
+
properties?: {
|
|
144
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
145
|
+
};
|
|
146
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
147
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
148
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
149
|
+
not?: ReferenceObject | SchemaObject;
|
|
150
|
+
nullable?: boolean;
|
|
151
|
+
discriminator?: DiscriminatorObject;
|
|
152
|
+
readOnly?: boolean;
|
|
153
|
+
writeOnly?: boolean;
|
|
154
|
+
xml?: XMLObject;
|
|
155
|
+
externalDocs?: ExternalDocumentationObject;
|
|
156
|
+
example?: any;
|
|
157
|
+
deprecated?: boolean;
|
|
158
|
+
}
|
|
159
|
+
interface DiscriminatorObject {
|
|
160
|
+
propertyName: string;
|
|
161
|
+
mapping?: {
|
|
162
|
+
[value: string]: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
interface XMLObject {
|
|
166
|
+
name?: string;
|
|
167
|
+
namespace?: string;
|
|
168
|
+
prefix?: string;
|
|
169
|
+
attribute?: boolean;
|
|
170
|
+
wrapped?: boolean;
|
|
171
|
+
}
|
|
172
|
+
interface ReferenceObject {
|
|
173
|
+
$ref: string;
|
|
174
|
+
}
|
|
175
|
+
interface ExampleObject {
|
|
176
|
+
summary?: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
value?: any;
|
|
179
|
+
externalValue?: string;
|
|
180
|
+
}
|
|
181
|
+
interface MediaTypeObject {
|
|
182
|
+
schema?: ReferenceObject | SchemaObject;
|
|
183
|
+
example?: any;
|
|
184
|
+
examples?: {
|
|
185
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
186
|
+
};
|
|
187
|
+
encoding?: {
|
|
188
|
+
[media: string]: EncodingObject;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
interface EncodingObject {
|
|
192
|
+
contentType?: string;
|
|
193
|
+
headers?: {
|
|
194
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
195
|
+
};
|
|
196
|
+
style?: string;
|
|
197
|
+
explode?: boolean;
|
|
198
|
+
allowReserved?: boolean;
|
|
199
|
+
}
|
|
200
|
+
interface RequestBodyObject {
|
|
201
|
+
description?: string;
|
|
202
|
+
content: {
|
|
203
|
+
[media: string]: MediaTypeObject;
|
|
204
|
+
};
|
|
205
|
+
required?: boolean;
|
|
206
|
+
}
|
|
207
|
+
interface ResponsesObject {
|
|
208
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
209
|
+
}
|
|
210
|
+
interface ResponseObject {
|
|
211
|
+
description: string;
|
|
212
|
+
headers?: {
|
|
213
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
214
|
+
};
|
|
215
|
+
content?: {
|
|
216
|
+
[media: string]: MediaTypeObject;
|
|
217
|
+
};
|
|
218
|
+
links?: {
|
|
219
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
interface LinkObject {
|
|
223
|
+
operationRef?: string;
|
|
224
|
+
operationId?: string;
|
|
225
|
+
parameters?: {
|
|
226
|
+
[parameter: string]: any;
|
|
227
|
+
};
|
|
228
|
+
requestBody?: any;
|
|
229
|
+
description?: string;
|
|
230
|
+
server?: ServerObject;
|
|
231
|
+
}
|
|
232
|
+
interface CallbackObject {
|
|
233
|
+
[url: string]: PathItemObject;
|
|
234
|
+
}
|
|
235
|
+
interface SecurityRequirementObject {
|
|
236
|
+
[name: string]: string[];
|
|
237
|
+
}
|
|
238
|
+
interface ComponentsObject {
|
|
239
|
+
schemas?: {
|
|
240
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
241
|
+
};
|
|
242
|
+
responses?: {
|
|
243
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
244
|
+
};
|
|
245
|
+
parameters?: {
|
|
246
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
247
|
+
};
|
|
248
|
+
examples?: {
|
|
249
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
250
|
+
};
|
|
251
|
+
requestBodies?: {
|
|
252
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
253
|
+
};
|
|
254
|
+
headers?: {
|
|
255
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
256
|
+
};
|
|
257
|
+
securitySchemes?: {
|
|
258
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
259
|
+
};
|
|
260
|
+
links?: {
|
|
261
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
262
|
+
};
|
|
263
|
+
callbacks?: {
|
|
264
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
268
|
+
interface HttpSecurityScheme {
|
|
269
|
+
type: 'http';
|
|
270
|
+
description?: string;
|
|
271
|
+
scheme: string;
|
|
272
|
+
bearerFormat?: string;
|
|
273
|
+
}
|
|
274
|
+
interface ApiKeySecurityScheme {
|
|
275
|
+
type: 'apiKey';
|
|
276
|
+
description?: string;
|
|
277
|
+
name: string;
|
|
278
|
+
in: string;
|
|
279
|
+
}
|
|
280
|
+
interface OAuth2SecurityScheme {
|
|
281
|
+
type: 'oauth2';
|
|
282
|
+
description?: string;
|
|
283
|
+
flows: {
|
|
284
|
+
implicit?: {
|
|
285
|
+
authorizationUrl: string;
|
|
286
|
+
refreshUrl?: string;
|
|
287
|
+
scopes: {
|
|
288
|
+
[scope: string]: string;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
password?: {
|
|
292
|
+
tokenUrl: string;
|
|
293
|
+
refreshUrl?: string;
|
|
294
|
+
scopes: {
|
|
295
|
+
[scope: string]: string;
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
clientCredentials?: {
|
|
299
|
+
tokenUrl: string;
|
|
300
|
+
refreshUrl?: string;
|
|
301
|
+
scopes: {
|
|
302
|
+
[scope: string]: string;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
authorizationCode?: {
|
|
306
|
+
authorizationUrl: string;
|
|
307
|
+
tokenUrl: string;
|
|
308
|
+
refreshUrl?: string;
|
|
309
|
+
scopes: {
|
|
310
|
+
[scope: string]: string;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
interface OpenIdSecurityScheme {
|
|
316
|
+
type: 'openIdConnect';
|
|
317
|
+
description?: string;
|
|
318
|
+
openIdConnectUrl: string;
|
|
319
|
+
}
|
|
320
|
+
interface TagObject {
|
|
321
|
+
name: string;
|
|
322
|
+
description?: string;
|
|
323
|
+
externalDocs?: ExternalDocumentationObject;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/types.d.ts
|
|
328
|
+
/**
|
|
329
|
+
* Content-type string for selecting request/response schemas from an OpenAPI spec.
|
|
330
|
+
* Supports `'application/json'` or any other media type.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* const ct: ContentType = 'application/vnd.api+json'
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
type ContentType = 'application/json' | (string & {});
|
|
338
|
+
/**
|
|
339
|
+
* Extended OpenAPI 3.0 schema object that includes OpenAPI 3.1 and JSON Schema fields.
|
|
340
|
+
* The parser uses these additional fields to handle newer spec versions.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const schema: SchemaObject = {
|
|
345
|
+
* type: 'string',
|
|
346
|
+
* const: 'dog',
|
|
347
|
+
* contentMediaType: 'application/octet-stream',
|
|
348
|
+
* }
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
type SchemaObject$1 = SchemaObject$2 & {
|
|
13
352
|
/**
|
|
14
|
-
* OAS 3.
|
|
353
|
+
* OAS 3.0 vendor extension: marks a schema as nullable without using `type: ['null', ...]`.
|
|
15
354
|
*/
|
|
16
355
|
'x-nullable'?: boolean;
|
|
17
356
|
/**
|
|
18
|
-
* OAS 3.1: constrains the schema to a single fixed value.
|
|
19
|
-
* Semantically equivalent to a one-item `enum`.
|
|
357
|
+
* OAS 3.1: constrains the schema to a single fixed value (equivalent to a one-item `enum`).
|
|
20
358
|
*/
|
|
21
359
|
const?: string | number | boolean | null;
|
|
22
360
|
/**
|
|
23
|
-
* OAS 3.1:
|
|
24
|
-
* When set to `'application/octet-stream'` on a `string` schema, the schema is treated as binary (`blob`).
|
|
361
|
+
* OAS 3.1: media type of the schema content. `'application/octet-stream'` on a `string` schema maps to `blob`.
|
|
25
362
|
*/
|
|
26
363
|
contentMediaType?: string;
|
|
27
364
|
$ref?: string;
|
|
28
365
|
/**
|
|
29
|
-
* OAS 3.1
|
|
30
|
-
* Replaces the OAS 3.0 multi-item `items` array syntax.
|
|
366
|
+
* OAS 3.1: positional tuple items, replacing the multi-item `items` array from OAS 3.0.
|
|
31
367
|
*/
|
|
32
|
-
prefixItems?: Array<SchemaObject$1 | ReferenceObject>;
|
|
368
|
+
prefixItems?: Array<SchemaObject$1 | ReferenceObject$1>;
|
|
33
369
|
/**
|
|
34
|
-
* JSON Schema: maps regex patterns to sub-schemas for additional
|
|
370
|
+
* JSON Schema: maps regex patterns to sub-schemas for validating additional properties.
|
|
35
371
|
*/
|
|
36
372
|
patternProperties?: Record<string, SchemaObject$1 | boolean>;
|
|
37
373
|
/**
|
|
38
|
-
*
|
|
39
|
-
* The OAS base type already includes this, but we re-declare it here to ensure
|
|
40
|
-
* the single-schema overload takes precedence over the multi-schema tuple form.
|
|
374
|
+
* Single-schema form of `items`. Narrowed from the base type to take precedence over the tuple overload.
|
|
41
375
|
*/
|
|
42
|
-
items?: SchemaObject$1 | ReferenceObject;
|
|
376
|
+
items?: SchemaObject$1 | ReferenceObject$1;
|
|
43
377
|
/**
|
|
44
|
-
* Enum values for this schema (narrowed from `unknown[]`
|
|
378
|
+
* Enum values for this schema (narrowed from `unknown[]`).
|
|
45
379
|
*/
|
|
46
380
|
enum?: Array<string | number | boolean | null>;
|
|
47
381
|
};
|
|
382
|
+
/**
|
|
383
|
+
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```ts
|
|
387
|
+
* HttpMethods['GET'] // 'get'
|
|
388
|
+
* HttpMethods['POST'] // 'post'
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
declare const HttpMethods$1: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
|
|
392
|
+
/**
|
|
393
|
+
* HTTP method as a lowercase string (`'get' | 'post' | ...`).
|
|
394
|
+
*/
|
|
395
|
+
type HttpMethod = Lowercase<ast.HttpMethod>;
|
|
396
|
+
/**
|
|
397
|
+
* Normalized OpenAPI document after parsing.
|
|
398
|
+
*/
|
|
48
399
|
type Document = OASDocument;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
getParameters(operation: Operation$1): Array<ParameterObject>;
|
|
85
|
-
getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
|
|
86
|
-
validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
87
|
-
flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
|
|
88
|
-
/**
|
|
89
|
-
* Get schemas from OpenAPI components (schemas, responses, requestBodies).
|
|
90
|
-
* Returns schemas in dependency order along with name mapping for collision resolution.
|
|
91
|
-
*/
|
|
92
|
-
getSchemas(options?: {
|
|
93
|
-
contentType?: contentType;
|
|
94
|
-
includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
95
|
-
collisionDetection?: boolean;
|
|
96
|
-
}): {
|
|
97
|
-
schemas: Record<string, SchemaObject$1>;
|
|
98
|
-
nameMapping: Map<string, string>;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/types.d.ts
|
|
103
|
-
type OasAdapterOptions = {
|
|
400
|
+
/**
|
|
401
|
+
* API operation extracted from an OpenAPI document.
|
|
402
|
+
*/
|
|
403
|
+
type Operation = Operation$1;
|
|
404
|
+
/**
|
|
405
|
+
* Discriminator object for `oneOf`/`anyOf` schemas in OpenAPI.
|
|
406
|
+
*/
|
|
407
|
+
type DiscriminatorObject$1 = DiscriminatorObject$2;
|
|
408
|
+
/**
|
|
409
|
+
* OpenAPI reference object pointing to a schema definition via `$ref`.
|
|
410
|
+
*/
|
|
411
|
+
type ReferenceObject$1 = OpenAPIV3.ReferenceObject;
|
|
412
|
+
/**
|
|
413
|
+
* OpenAPI response object from a spec that contains schema, status code, and headers.
|
|
414
|
+
*/
|
|
415
|
+
type ResponseObject$1 = ResponseObject$2;
|
|
416
|
+
/**
|
|
417
|
+
* OpenAPI media type object that maps a content-type string to its schema.
|
|
418
|
+
*/
|
|
419
|
+
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
420
|
+
/**
|
|
421
|
+
* Configuration options for the OpenAPI adapter.
|
|
422
|
+
* Controls spec validation, content-type selection, and server URL resolution.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* adapterOas({
|
|
427
|
+
* validate: false,
|
|
428
|
+
* dateType: 'date',
|
|
429
|
+
* serverIndex: 0,
|
|
430
|
+
* serverVariables: { env: 'prod' },
|
|
431
|
+
* })
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
type AdapterOasOptions = {
|
|
104
435
|
/**
|
|
105
436
|
* Validate the OpenAPI spec before parsing.
|
|
106
437
|
* @default true
|
|
107
438
|
*/
|
|
108
439
|
validate?: boolean;
|
|
109
440
|
/**
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
oasClass?: typeof Oas;
|
|
113
|
-
/**
|
|
114
|
-
* Restrict which content-type is used when extracting request/response schemas.
|
|
115
|
-
* By default, the first valid JSON media type is used.
|
|
441
|
+
* Preferred content-type used when extracting request/response schemas.
|
|
442
|
+
* Defaults to the first valid JSON media type found in the spec.
|
|
116
443
|
*/
|
|
117
|
-
contentType?:
|
|
444
|
+
contentType?: ContentType;
|
|
118
445
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* - When omitted, `baseURL` in the resulting `RootNode.meta` is `undefined`.
|
|
446
|
+
* Index into `oas.api.servers` for computing `baseURL`.
|
|
447
|
+
* `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.
|
|
122
448
|
*/
|
|
123
449
|
serverIndex?: number;
|
|
124
450
|
/**
|
|
@@ -126,89 +452,141 @@ type OasAdapterOptions = {
|
|
|
126
452
|
* Only used when `serverIndex` is set.
|
|
127
453
|
*
|
|
128
454
|
* @example
|
|
455
|
+
* ```ts
|
|
129
456
|
* // spec server: "https://api.{env}.example.com"
|
|
130
457
|
* serverVariables: { env: 'prod' }
|
|
131
458
|
* // → baseURL: "https://api.prod.example.com"
|
|
459
|
+
* ```
|
|
132
460
|
*/
|
|
133
461
|
serverVariables?: Record<string, string>;
|
|
134
462
|
/**
|
|
135
|
-
* How the discriminator field
|
|
136
|
-
* - `'strict'` — uses `oneOf` schemas as
|
|
137
|
-
* - `'inherit'` —
|
|
463
|
+
* How the discriminator field is interpreted.
|
|
464
|
+
* - `'strict'` — uses `oneOf` schemas as written in the spec.
|
|
465
|
+
* - `'inherit'` — propagates discriminator values into child schemas from `discriminator.mapping`.
|
|
138
466
|
* @default 'strict'
|
|
139
467
|
*/
|
|
140
468
|
discriminator?: 'strict' | 'inherit';
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* How `format: 'date-time'` schemas are represented in the AST.
|
|
148
|
-
* - `'string'` maps to a `datetime` string node.
|
|
149
|
-
* - `'date'` maps to a JavaScript `Date` node.
|
|
150
|
-
* - `false` falls through to a plain `string` node.
|
|
151
|
-
* @default 'string'
|
|
152
|
-
*/
|
|
153
|
-
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
154
|
-
/**
|
|
155
|
-
* Whether `type: 'integer'` / `format: 'int64'` produces `number` or `bigint` nodes.
|
|
156
|
-
* @default 'number'
|
|
157
|
-
*/
|
|
158
|
-
integerType?: 'number' | 'bigint';
|
|
159
|
-
/**
|
|
160
|
-
* AST type used when no schema type can be inferred.
|
|
161
|
-
* @default 'any'
|
|
162
|
-
*/
|
|
163
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
164
|
-
/**
|
|
165
|
-
* AST type used for completely empty schemas (`{}`).
|
|
166
|
-
* @default `unknownType`
|
|
167
|
-
*/
|
|
168
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
169
|
-
};
|
|
170
|
-
type OasAdapterResolvedOptions = {
|
|
469
|
+
} & Partial<ast.ParserOptions>;
|
|
470
|
+
/**
|
|
471
|
+
* Adapter options after defaults have been applied and schema name collisions resolved.
|
|
472
|
+
*/
|
|
473
|
+
type AdapterOasResolvedOptions = {
|
|
171
474
|
validate: boolean;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
|
|
475
|
+
contentType: AdapterOasOptions['contentType'];
|
|
476
|
+
serverIndex: AdapterOasOptions['serverIndex'];
|
|
477
|
+
serverVariables: AdapterOasOptions['serverVariables'];
|
|
478
|
+
discriminator: NonNullable<AdapterOasOptions['discriminator']>;
|
|
479
|
+
dateType: NonNullable<AdapterOasOptions['dateType']>;
|
|
480
|
+
integerType: NonNullable<AdapterOasOptions['integerType']>;
|
|
481
|
+
unknownType: NonNullable<AdapterOasOptions['unknownType']>;
|
|
482
|
+
emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>;
|
|
483
|
+
enumSuffix: AdapterOasOptions['enumSuffix'];
|
|
182
484
|
/**
|
|
183
485
|
* Map from original `$ref` paths to their collision-resolved schema names.
|
|
184
|
-
* Populated
|
|
185
|
-
*
|
|
486
|
+
* Populated after each `parse()` call.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts
|
|
490
|
+
* nameMapping.get('#/components/schemas/Order') // 'Order'
|
|
491
|
+
* nameMapping.get('#/components/responses/Order') // 'OrderResponse'
|
|
492
|
+
* ```
|
|
186
493
|
*/
|
|
187
494
|
nameMapping: Map<string, string>;
|
|
188
495
|
};
|
|
189
|
-
|
|
496
|
+
/**
|
|
497
|
+
* `@kubb/core` adapter factory type for the OpenAPI adapter.
|
|
498
|
+
*/
|
|
499
|
+
type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions, Document>;
|
|
190
500
|
//#endregion
|
|
191
501
|
//#region src/adapter.d.ts
|
|
502
|
+
/**
|
|
503
|
+
* Stable string identifier for the OAS adapter used in Kubb's adapter registry.
|
|
504
|
+
*/
|
|
192
505
|
declare const adapterOasName = "oas";
|
|
193
506
|
/**
|
|
194
|
-
* Creates
|
|
507
|
+
* Creates the default OpenAPI / Swagger adapter for Kubb.
|
|
195
508
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
509
|
+
* Parses the spec, optionally validates it, resolves the base URL, and converts
|
|
510
|
+
* everything into an `InputNode` that downstream plugins consume.
|
|
198
511
|
*
|
|
199
512
|
* @example
|
|
200
513
|
* ```ts
|
|
201
|
-
* import { defineConfig } from '
|
|
514
|
+
* import { defineConfig } from 'kubb'
|
|
202
515
|
* import { adapterOas } from '@kubb/adapter-oas'
|
|
516
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
203
517
|
*
|
|
204
518
|
* export default defineConfig({
|
|
205
|
-
* adapter: adapterOas({
|
|
206
|
-
* input:
|
|
207
|
-
* plugins: [pluginTs()
|
|
519
|
+
* adapter: adapterOas({ dateType: 'date', serverIndex: 0 }),
|
|
520
|
+
* input: { path: './openapi.yaml' },
|
|
521
|
+
* plugins: [pluginTs()],
|
|
208
522
|
* })
|
|
209
523
|
* ```
|
|
210
524
|
*/
|
|
211
|
-
declare const adapterOas: (options?:
|
|
525
|
+
declare const adapterOas: (options?: AdapterOasOptions | undefined) => _$_kubb_core0.Adapter<AdapterOas>;
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/factory.d.ts
|
|
528
|
+
type ParseOptions = {
|
|
529
|
+
canBundle?: boolean;
|
|
530
|
+
enablePaths?: boolean;
|
|
531
|
+
};
|
|
532
|
+
type ValidateDocumentOptions = {
|
|
533
|
+
throwOnError?: boolean;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* Loads and dereferences an OpenAPI document, returning the raw `Document`.
|
|
537
|
+
*
|
|
538
|
+
* Accepts a file path string or an already-parsed document object. File paths are bundled via
|
|
539
|
+
* Redocly to resolve external `$ref`s. Swagger 2.0 documents are automatically up-converted
|
|
540
|
+
* to OpenAPI 3.0 via `swagger2openapi`.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```ts
|
|
544
|
+
* const document = await parseDocument('./openapi.yaml')
|
|
545
|
+
* const document = await parse(rawDocumentObject, { canBundle: false })
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
declare function parseDocument(pathOrApi: string | Document, {
|
|
549
|
+
canBundle,
|
|
550
|
+
enablePaths
|
|
551
|
+
}?: ParseOptions): Promise<Document>;
|
|
552
|
+
/**
|
|
553
|
+
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
554
|
+
*
|
|
555
|
+
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
556
|
+
* Throws when the input array is empty.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* const document = await mergeDocuments(['./pets.yaml', './orders.yaml'])
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
declare function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document>;
|
|
564
|
+
/**
|
|
565
|
+
* Creates a `Document` from an `AdapterSource`.
|
|
566
|
+
*
|
|
567
|
+
* Handles all three source types:
|
|
568
|
+
* - `{ type: 'path' }` — resolves and bundles a local file path or remote URL.
|
|
569
|
+
* - `{ type: 'paths' }` — merges multiple file paths into a single document.
|
|
570
|
+
* - `{ type: 'data' }` — parses an inline string (YAML/JSON) or raw object.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```ts
|
|
574
|
+
* const document = await parseFromConfig({ type: 'path', path: './openapi.yaml' })
|
|
575
|
+
* const document = await parseFromConfig({ type: 'data', data: '{"openapi":"3.0.0",...}' })
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
declare function parseFromConfig(source: AdapterSource): Promise<Document>;
|
|
579
|
+
/**
|
|
580
|
+
* Validates an OpenAPI document using `oas-normalize` with colorized error output.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* await validateDocument(document)
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
declare function validateDocument(document: Document, {
|
|
588
|
+
throwOnError
|
|
589
|
+
}?: ValidateDocumentOptions): Promise<void>;
|
|
212
590
|
//#endregion
|
|
213
|
-
export { adapterOas, adapterOasName };
|
|
591
|
+
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject$1 as DiscriminatorObject, type Document, type HttpMethod, HttpMethods$1 as HttpMethods, type MediaTypeObject$1 as MediaTypeObject, type Operation, type ParseOptions, type ReferenceObject$1 as ReferenceObject, type ResponseObject$1 as ResponseObject, type SchemaObject$1 as SchemaObject, type ValidateDocumentOptions, adapterOas, adapterOasName, mergeDocuments, parseDocument, parseFromConfig, validateDocument };
|
|
214
592
|
//# sourceMappingURL=index.d.ts.map
|