@kubb/adapter-oas 5.0.0-alpha.41 → 5.0.0-alpha.43
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 +51 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +333 -14
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/adapter.ts +1 -1
- package/src/factory.ts +8 -12
- package/src/guards.ts +1 -1
- package/src/index.ts +2 -2
- package/src/parser.ts +14 -8
- package/src/refs.ts +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,329 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
3
3
|
import { AdapterFactoryOptions, AdapterSource, ast } from "@kubb/core";
|
|
4
|
-
import { DiscriminatorObject as DiscriminatorObject$
|
|
4
|
+
import { DiscriminatorObject as DiscriminatorObject$2, MediaTypeObject as MediaTypeObject$2, OASDocument, ResponseObject as ResponseObject$2, SchemaObject as SchemaObject$2 } from "oas/types";
|
|
5
5
|
import { Operation as Operation$1 } from "oas/operation";
|
|
6
|
-
import { OpenAPIV3 } from "openapi-types";
|
|
7
6
|
|
|
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
|
|
8
327
|
//#region src/types.d.ts
|
|
9
328
|
/**
|
|
10
329
|
* Content-type string used when selecting request/response schemas from a spec.
|
|
@@ -29,7 +348,7 @@ type ContentType = 'application/json' | (string & {});
|
|
|
29
348
|
* }
|
|
30
349
|
* ```
|
|
31
350
|
*/
|
|
32
|
-
type SchemaObject = SchemaObject$
|
|
351
|
+
type SchemaObject$1 = SchemaObject$2 & {
|
|
33
352
|
/**
|
|
34
353
|
* OAS 3.0 vendor extension: marks a schema as nullable without using `type: ['null', ...]`.
|
|
35
354
|
*/
|
|
@@ -46,15 +365,15 @@ type SchemaObject = SchemaObject$1 & {
|
|
|
46
365
|
/**
|
|
47
366
|
* OAS 3.1: positional tuple items, replacing the multi-item `items` array from OAS 3.0.
|
|
48
367
|
*/
|
|
49
|
-
prefixItems?: Array<SchemaObject | ReferenceObject>;
|
|
368
|
+
prefixItems?: Array<SchemaObject$1 | ReferenceObject$1>;
|
|
50
369
|
/**
|
|
51
370
|
* JSON Schema: maps regex patterns to sub-schemas for validating additional properties.
|
|
52
371
|
*/
|
|
53
|
-
patternProperties?: Record<string, SchemaObject | boolean>;
|
|
372
|
+
patternProperties?: Record<string, SchemaObject$1 | boolean>;
|
|
54
373
|
/**
|
|
55
374
|
* Single-schema form of `items`. Narrowed from the base type to take precedence over the tuple overload.
|
|
56
375
|
*/
|
|
57
|
-
items?: SchemaObject | ReferenceObject;
|
|
376
|
+
items?: SchemaObject$1 | ReferenceObject$1;
|
|
58
377
|
/**
|
|
59
378
|
* Enum values for this schema (narrowed from `unknown[]`).
|
|
60
379
|
*/
|
|
@@ -69,7 +388,7 @@ type SchemaObject = SchemaObject$1 & {
|
|
|
69
388
|
* HttpMethods['POST'] // 'post'
|
|
70
389
|
* ```
|
|
71
390
|
*/
|
|
72
|
-
declare const HttpMethods: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
|
|
391
|
+
declare const HttpMethods$1: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
|
|
73
392
|
/**
|
|
74
393
|
* Lowercase HTTP method string as used by the `oas` package (`'get' | 'post' | ...`).
|
|
75
394
|
*/
|
|
@@ -85,19 +404,19 @@ type Operation = Operation$1;
|
|
|
85
404
|
/**
|
|
86
405
|
* OpenAPI `discriminator` object attached to a `oneOf`/`anyOf` schema.
|
|
87
406
|
*/
|
|
88
|
-
type DiscriminatorObject = DiscriminatorObject$
|
|
407
|
+
type DiscriminatorObject$1 = DiscriminatorObject$2;
|
|
89
408
|
/**
|
|
90
409
|
* OpenAPI `$ref` pointer object (`{ $ref: string }`).
|
|
91
410
|
*/
|
|
92
|
-
type ReferenceObject = OpenAPIV3.ReferenceObject;
|
|
411
|
+
type ReferenceObject$1 = OpenAPIV3.ReferenceObject;
|
|
93
412
|
/**
|
|
94
413
|
* OpenAPI response object type (may contain `content`, `description`, `headers`).
|
|
95
414
|
*/
|
|
96
|
-
type ResponseObject = ResponseObject$
|
|
415
|
+
type ResponseObject$1 = ResponseObject$2;
|
|
97
416
|
/**
|
|
98
417
|
* OpenAPI media type object that maps a content-type to a schema.
|
|
99
418
|
*/
|
|
100
|
-
type MediaTypeObject = MediaTypeObject$
|
|
419
|
+
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
101
420
|
/**
|
|
102
421
|
* User-facing options for `adapterOas(...)`.
|
|
103
422
|
*
|
|
@@ -194,7 +513,7 @@ declare const adapterOasName = "oas";
|
|
|
194
513
|
*
|
|
195
514
|
* @example
|
|
196
515
|
* ```ts
|
|
197
|
-
* import { defineConfig } from '
|
|
516
|
+
* import { defineConfig } from 'kubb'
|
|
198
517
|
* import { adapterOas } from '@kubb/adapter-oas'
|
|
199
518
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
200
519
|
*
|
|
@@ -235,7 +554,7 @@ declare function parseDocument(pathOrApi: string | Document, {
|
|
|
235
554
|
/**
|
|
236
555
|
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
237
556
|
*
|
|
238
|
-
* Each document is parsed independently then recursively merged
|
|
557
|
+
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
239
558
|
* Throws when the input array is empty.
|
|
240
559
|
*
|
|
241
560
|
* @example
|
|
@@ -271,5 +590,5 @@ declare function validateDocument(document: Document, {
|
|
|
271
590
|
throwOnError
|
|
272
591
|
}?: ValidateDocumentOptions): Promise<void>;
|
|
273
592
|
//#endregion
|
|
274
|
-
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject, type Document, type HttpMethod, HttpMethods, type MediaTypeObject, type Operation, type ParseOptions, type ReferenceObject, type ResponseObject, type SchemaObject, type ValidateDocumentOptions, adapterOas, adapterOasName, mergeDocuments, parseDocument, parseFromConfig, validateDocument };
|
|
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 };
|
|
275
594
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,9 @@ import "./chunk--u3MIqq1.js";
|
|
|
2
2
|
import { ast, createAdapter } from "@kubb/core";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { bundle, loadConfig } from "@redocly/openapi-core";
|
|
5
|
-
import yaml from "@stoplight/yaml";
|
|
6
5
|
import OASNormalize from "oas-normalize";
|
|
7
|
-
import { isPlainObject, mergeDeep } from "remeda";
|
|
8
6
|
import swagger2openapi from "swagger2openapi";
|
|
9
7
|
import BaseOas from "oas";
|
|
10
|
-
import jsonpointer from "jsonpointer";
|
|
11
8
|
import { isRef } from "oas/types";
|
|
12
9
|
import { matchesMimeType } from "oas/utils";
|
|
13
10
|
//#region src/constants.ts
|
|
@@ -258,6 +255,40 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
258
255
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
259
256
|
}
|
|
260
257
|
//#endregion
|
|
258
|
+
//#region ../../internals/utils/src/object.ts
|
|
259
|
+
/**
|
|
260
|
+
* Returns `true` when `value` is a plain (non-null, non-array) object.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* isPlainObject({}) // true
|
|
265
|
+
* isPlainObject([]) // false
|
|
266
|
+
* isPlainObject(null) // false
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
function isPlainObject(value) {
|
|
270
|
+
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Recursively merges `source` into `target`, combining nested plain objects.
|
|
274
|
+
* Arrays and non-object values from `source` override the corresponding values in `target`.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* mergeDeep({ a: { x: 1 } }, { a: { y: 2 } })
|
|
279
|
+
* // { a: { x: 1, y: 2 } }
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
function mergeDeep(target, source) {
|
|
283
|
+
const result = { ...target };
|
|
284
|
+
for (const key of Object.keys(source)) {
|
|
285
|
+
const sv = source[key];
|
|
286
|
+
const tv = result[key];
|
|
287
|
+
result[key] = sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv) ? mergeDeep(tv, sv) : sv;
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
261
292
|
//#region ../../internals/utils/src/reserved.ts
|
|
262
293
|
/**
|
|
263
294
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
@@ -520,7 +551,7 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
|
|
|
520
551
|
/**
|
|
521
552
|
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
522
553
|
*
|
|
523
|
-
* Each document is parsed independently then recursively merged
|
|
554
|
+
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
524
555
|
* Throws when the input array is empty.
|
|
525
556
|
*
|
|
526
557
|
* @example
|
|
@@ -563,11 +594,7 @@ async function mergeDocuments(pathOrApi) {
|
|
|
563
594
|
function parseFromConfig(source) {
|
|
564
595
|
if (source.type === "data") {
|
|
565
596
|
if (typeof source.data === "object") return parseDocument(structuredClone(source.data));
|
|
566
|
-
|
|
567
|
-
return parseDocument(yaml.parse(source.data));
|
|
568
|
-
} catch {
|
|
569
|
-
return parseDocument(source.data);
|
|
570
|
-
}
|
|
597
|
+
return parseDocument(source.data, { canBundle: false });
|
|
571
598
|
}
|
|
572
599
|
if (source.type === "paths") return mergeDocuments(source.paths);
|
|
573
600
|
if (new URLPath(source.path).isURL) return parseDocument(source.path);
|
|
@@ -610,7 +637,7 @@ function resolveRef(document, $ref) {
|
|
|
610
637
|
if ($ref === "") return null;
|
|
611
638
|
if ($ref.startsWith("#")) $ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
612
639
|
else return null;
|
|
613
|
-
const current =
|
|
640
|
+
const current = $ref.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
|
|
614
641
|
if (!current) throw new Error(`Could not find a definition for ${origRef}.`);
|
|
615
642
|
return current;
|
|
616
643
|
}
|
|
@@ -1295,15 +1322,21 @@ function createSchemaParser(ctx) {
|
|
|
1295
1322
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
1296
1323
|
if (extensionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1297
1324
|
const enumPrimitiveType = enumPrimitive === "number" || enumPrimitive === "integer" ? "number" : enumPrimitive === "boolean" ? "boolean" : "string";
|
|
1298
|
-
const
|
|
1325
|
+
const rawEnumNames = extensionKey ? schema[extensionKey] : void 0;
|
|
1326
|
+
const uniqueValues = [...new Set(filteredValues)];
|
|
1327
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1299
1328
|
return ast.createSchema({
|
|
1300
1329
|
...enumBase,
|
|
1301
1330
|
primitive: enumPrimitiveType,
|
|
1302
|
-
namedEnumValues:
|
|
1303
|
-
name: String(
|
|
1304
|
-
value
|
|
1331
|
+
namedEnumValues: uniqueValues.map((value, index) => ({
|
|
1332
|
+
name: String(rawEnumNames?.[index] ?? value),
|
|
1333
|
+
value,
|
|
1305
1334
|
primitive: enumPrimitiveType
|
|
1306
|
-
}))
|
|
1335
|
+
})).filter((entry) => {
|
|
1336
|
+
if (seenNames.has(entry.name)) return false;
|
|
1337
|
+
seenNames.add(entry.name);
|
|
1338
|
+
return true;
|
|
1339
|
+
})
|
|
1307
1340
|
});
|
|
1308
1341
|
}
|
|
1309
1342
|
return ast.createSchema({
|
|
@@ -1664,7 +1697,7 @@ const adapterOasName = "oas";
|
|
|
1664
1697
|
*
|
|
1665
1698
|
* @example
|
|
1666
1699
|
* ```ts
|
|
1667
|
-
* import { defineConfig } from '
|
|
1700
|
+
* import { defineConfig } from 'kubb'
|
|
1668
1701
|
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1669
1702
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1670
1703
|
*
|