@kubb/adapter-oas 5.0.0-alpha.7 → 5.0.0-alpha.70
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 +1203 -1215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +524 -135
- package/dist/index.js +1194 -1209
- package/dist/index.js.map +1 -1
- package/package.json +32 -35
- package/src/adapter.ts +82 -78
- package/src/constants.ts +78 -66
- 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 +546 -655
- package/src/refs.ts +59 -0
- package/src/resolvers.ts +552 -0
- package/src/types.ts +174 -59
- package/src/oas/Oas.ts +0 -616
- 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 -161
package/dist/index.d.ts
CHANGED
|
@@ -1,115 +1,452 @@
|
|
|
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, SchemaObject } from "oas/types";
|
|
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 used when selecting request/response schemas from a spec.
|
|
330
|
+
*
|
|
331
|
+
* Accepts `'application/json'` or any arbitrary media type string.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```ts
|
|
335
|
+
* const ct: contentType = 'application/vnd.api+json'
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
type ContentType = 'application/json' | (string & {});
|
|
339
|
+
/**
|
|
340
|
+
* Augments `oas`'s `SchemaObject` with OAS 3.1 / JSON Schema fields the parser needs.
|
|
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
|
+
* Uppercase → lowercase HTTP method map, re-exported 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
|
+
* Lowercase HTTP method string as used by the `oas` package (`'get' | 'post' | ...`).
|
|
394
|
+
*/
|
|
395
|
+
type HttpMethod = Lowercase<ast.HttpMethod>;
|
|
396
|
+
/**
|
|
397
|
+
* Normalized OpenAPI document type used throughout the adapter.
|
|
398
|
+
*/
|
|
48
399
|
type Document = OASDocument;
|
|
49
|
-
|
|
50
|
-
type
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
collisionDetection?: boolean;
|
|
87
|
-
}): {
|
|
88
|
-
schemas: Record<string, SchemaObject$1>;
|
|
89
|
-
nameMapping: Map<string, string>;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/types.d.ts
|
|
94
|
-
type OasAdapterOptions = {
|
|
400
|
+
/**
|
|
401
|
+
* Operation wrapper type returned by the `oas` package.
|
|
402
|
+
*/
|
|
403
|
+
type Operation = Operation$1;
|
|
404
|
+
/**
|
|
405
|
+
* OpenAPI `discriminator` object attached to a `oneOf`/`anyOf` schema.
|
|
406
|
+
*/
|
|
407
|
+
type DiscriminatorObject$1 = DiscriminatorObject$2;
|
|
408
|
+
/**
|
|
409
|
+
* OpenAPI `$ref` pointer object (`{ $ref: string }`).
|
|
410
|
+
*/
|
|
411
|
+
type ReferenceObject$1 = OpenAPIV3.ReferenceObject;
|
|
412
|
+
/**
|
|
413
|
+
* OpenAPI response object type (may contain `content`, `description`, `headers`).
|
|
414
|
+
*/
|
|
415
|
+
type ResponseObject$1 = ResponseObject$2;
|
|
416
|
+
/**
|
|
417
|
+
* OpenAPI media type object that maps a content-type to a schema.
|
|
418
|
+
*/
|
|
419
|
+
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
420
|
+
/**
|
|
421
|
+
* User-facing options for `adapterOas(...)`.
|
|
422
|
+
*
|
|
423
|
+
* Extends `ParserOptions` from `@kubb/ast` with adapter-specific controls
|
|
424
|
+
* like spec validation and server URL selection.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* adapterOas({
|
|
429
|
+
* validate: false,
|
|
430
|
+
* dateType: 'date',
|
|
431
|
+
* serverIndex: 0,
|
|
432
|
+
* serverVariables: { env: 'prod' },
|
|
433
|
+
* })
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
type AdapterOasOptions = {
|
|
95
437
|
/**
|
|
96
438
|
* Validate the OpenAPI spec before parsing.
|
|
97
439
|
* @default true
|
|
98
440
|
*/
|
|
99
441
|
validate?: boolean;
|
|
100
442
|
/**
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
oasClass?: typeof Oas;
|
|
104
|
-
/**
|
|
105
|
-
* Restrict which content-type is used when extracting request/response schemas.
|
|
106
|
-
* By default, the first valid JSON media type is used.
|
|
443
|
+
* Preferred content-type used when extracting request/response schemas.
|
|
444
|
+
* Defaults to the first valid JSON media type found in the spec.
|
|
107
445
|
*/
|
|
108
|
-
contentType?:
|
|
446
|
+
contentType?: ContentType;
|
|
109
447
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* - When omitted, `baseURL` in the resulting `RootNode.meta` is `undefined`.
|
|
448
|
+
* Index into `oas.api.servers` for computing `baseURL`.
|
|
449
|
+
* `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.
|
|
113
450
|
*/
|
|
114
451
|
serverIndex?: number;
|
|
115
452
|
/**
|
|
@@ -117,89 +454,141 @@ type OasAdapterOptions = {
|
|
|
117
454
|
* Only used when `serverIndex` is set.
|
|
118
455
|
*
|
|
119
456
|
* @example
|
|
457
|
+
* ```ts
|
|
120
458
|
* // spec server: "https://api.{env}.example.com"
|
|
121
459
|
* serverVariables: { env: 'prod' }
|
|
122
460
|
* // → baseURL: "https://api.prod.example.com"
|
|
461
|
+
* ```
|
|
123
462
|
*/
|
|
124
463
|
serverVariables?: Record<string, string>;
|
|
125
464
|
/**
|
|
126
|
-
* How the discriminator field
|
|
127
|
-
* - `'strict'` — uses `oneOf` schemas as
|
|
128
|
-
* - `'inherit'` —
|
|
465
|
+
* How the discriminator field is interpreted.
|
|
466
|
+
* - `'strict'` — uses `oneOf` schemas as written in the spec.
|
|
467
|
+
* - `'inherit'` — propagates discriminator values into child schemas from `discriminator.mapping`.
|
|
129
468
|
* @default 'strict'
|
|
130
469
|
*/
|
|
131
470
|
discriminator?: 'strict' | 'inherit';
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* How `format: 'date-time'` schemas are represented in the AST.
|
|
139
|
-
* - `'string'` maps to a `datetime` string node.
|
|
140
|
-
* - `'date'` maps to a JavaScript `Date` node.
|
|
141
|
-
* - `false` falls through to a plain `string` node.
|
|
142
|
-
* @default 'string'
|
|
143
|
-
*/
|
|
144
|
-
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
145
|
-
/**
|
|
146
|
-
* Whether `type: 'integer'` / `format: 'int64'` produces `number` or `bigint` nodes.
|
|
147
|
-
* @default 'number'
|
|
148
|
-
*/
|
|
149
|
-
integerType?: 'number' | 'bigint';
|
|
150
|
-
/**
|
|
151
|
-
* AST type used when no schema type can be inferred.
|
|
152
|
-
* @default 'any'
|
|
153
|
-
*/
|
|
154
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
155
|
-
/**
|
|
156
|
-
* AST type used for completely empty schemas (`{}`).
|
|
157
|
-
* @default `unknownType`
|
|
158
|
-
*/
|
|
159
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
160
|
-
};
|
|
161
|
-
type OasAdapterResolvedOptions = {
|
|
471
|
+
} & Partial<ast.ParserOptions>;
|
|
472
|
+
/**
|
|
473
|
+
* Resolved adapter options available at runtime after defaults have been applied.
|
|
474
|
+
*/
|
|
475
|
+
type AdapterOasResolvedOptions = {
|
|
162
476
|
validate: boolean;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
|
|
477
|
+
contentType: AdapterOasOptions['contentType'];
|
|
478
|
+
serverIndex: AdapterOasOptions['serverIndex'];
|
|
479
|
+
serverVariables: AdapterOasOptions['serverVariables'];
|
|
480
|
+
discriminator: NonNullable<AdapterOasOptions['discriminator']>;
|
|
481
|
+
dateType: NonNullable<AdapterOasOptions['dateType']>;
|
|
482
|
+
integerType: NonNullable<AdapterOasOptions['integerType']>;
|
|
483
|
+
unknownType: NonNullable<AdapterOasOptions['unknownType']>;
|
|
484
|
+
emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>;
|
|
485
|
+
enumSuffix: AdapterOasOptions['enumSuffix'];
|
|
173
486
|
/**
|
|
174
487
|
* Map from original `$ref` paths to their collision-resolved schema names.
|
|
175
|
-
* Populated
|
|
176
|
-
*
|
|
488
|
+
* Populated after each `parse()` call.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* nameMapping.get('#/components/schemas/Order') // 'Order'
|
|
493
|
+
* nameMapping.get('#/components/responses/Order') // 'OrderResponse'
|
|
494
|
+
* ```
|
|
177
495
|
*/
|
|
178
496
|
nameMapping: Map<string, string>;
|
|
179
497
|
};
|
|
180
|
-
|
|
498
|
+
/**
|
|
499
|
+
* `@kubb/core` adapter factory type for the OpenAPI adapter.
|
|
500
|
+
*/
|
|
501
|
+
type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions, Document>;
|
|
181
502
|
//#endregion
|
|
182
503
|
//#region src/adapter.d.ts
|
|
504
|
+
/**
|
|
505
|
+
* Stable string identifier for the OAS adapter used in Kubb's adapter registry.
|
|
506
|
+
*/
|
|
183
507
|
declare const adapterOasName = "oas";
|
|
184
508
|
/**
|
|
185
|
-
* Creates
|
|
509
|
+
* Creates the default OpenAPI / Swagger adapter for Kubb.
|
|
186
510
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
511
|
+
* Parses the spec, optionally validates it, resolves the base URL, and converts
|
|
512
|
+
* everything into an `InputNode` that downstream plugins consume.
|
|
189
513
|
*
|
|
190
514
|
* @example
|
|
191
515
|
* ```ts
|
|
192
|
-
* import { defineConfig } from '
|
|
516
|
+
* import { defineConfig } from 'kubb'
|
|
193
517
|
* import { adapterOas } from '@kubb/adapter-oas'
|
|
518
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
194
519
|
*
|
|
195
520
|
* export default defineConfig({
|
|
196
|
-
* adapter: adapterOas({
|
|
197
|
-
* input:
|
|
198
|
-
* plugins: [pluginTs()
|
|
521
|
+
* adapter: adapterOas({ dateType: 'date', serverIndex: 0 }),
|
|
522
|
+
* input: { path: './openapi.yaml' },
|
|
523
|
+
* plugins: [pluginTs()],
|
|
199
524
|
* })
|
|
200
525
|
* ```
|
|
201
526
|
*/
|
|
202
|
-
declare const adapterOas: (options?:
|
|
527
|
+
declare const adapterOas: (options?: AdapterOasOptions | undefined) => _$_kubb_core0.Adapter<AdapterOas>;
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/factory.d.ts
|
|
530
|
+
type ParseOptions = {
|
|
531
|
+
canBundle?: boolean;
|
|
532
|
+
enablePaths?: boolean;
|
|
533
|
+
};
|
|
534
|
+
type ValidateDocumentOptions = {
|
|
535
|
+
throwOnError?: boolean;
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Loads and dereferences an OpenAPI document, returning the raw `Document`.
|
|
539
|
+
*
|
|
540
|
+
* Accepts a file path string or an already-parsed document object. File paths are bundled via
|
|
541
|
+
* Redocly to resolve external `$ref`s. Swagger 2.0 documents are automatically up-converted
|
|
542
|
+
* to OpenAPI 3.0 via `swagger2openapi`.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* const document = await parseDocument('./openapi.yaml')
|
|
547
|
+
* const document = await parse(rawDocumentObject, { canBundle: false })
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare function parseDocument(pathOrApi: string | Document, {
|
|
551
|
+
canBundle,
|
|
552
|
+
enablePaths
|
|
553
|
+
}?: ParseOptions): Promise<Document>;
|
|
554
|
+
/**
|
|
555
|
+
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
556
|
+
*
|
|
557
|
+
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
558
|
+
* Throws when the input array is empty.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* const document = await mergeDocuments(['./pets.yaml', './orders.yaml'])
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
declare function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document>;
|
|
566
|
+
/**
|
|
567
|
+
* Creates a `Document` from an `AdapterSource`.
|
|
568
|
+
*
|
|
569
|
+
* Handles all three source types:
|
|
570
|
+
* - `{ type: 'path' }` — resolves and bundles a local file path or remote URL.
|
|
571
|
+
* - `{ type: 'paths' }` — merges multiple file paths into a single document.
|
|
572
|
+
* - `{ type: 'data' }` — parses an inline string (YAML/JSON) or raw object.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* const document = await parseFromConfig({ type: 'path', path: './openapi.yaml' })
|
|
577
|
+
* const document = await parseFromConfig({ type: 'data', data: '{"openapi":"3.0.0",...}' })
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
declare function parseFromConfig(source: AdapterSource): Promise<Document>;
|
|
581
|
+
/**
|
|
582
|
+
* Validates an OpenAPI document using `oas-normalize` with colorized error output.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```ts
|
|
586
|
+
* await validateDocument(document)
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
declare function validateDocument(document: Document, {
|
|
590
|
+
throwOnError
|
|
591
|
+
}?: ValidateDocumentOptions): Promise<void>;
|
|
203
592
|
//#endregion
|
|
204
|
-
export { adapterOas, adapterOasName };
|
|
593
|
+
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 };
|
|
205
594
|
//# sourceMappingURL=index.d.ts.map
|