@kubb/adapter-oas 5.0.0-alpha.10 → 5.0.0-alpha.11
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 +201 -147
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +34 -26
- package/dist/index.js +201 -147
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter.ts +9 -6
- package/src/constants.ts +11 -5
- package/src/parser.ts +102 -77
- package/src/types.ts +35 -19
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,110 @@ jsonpointer = __toESM(jsonpointer);
|
|
|
39
39
|
let oas = require("oas");
|
|
40
40
|
oas = __toESM(oas);
|
|
41
41
|
let oas_utils = require("oas/utils");
|
|
42
|
+
//#region src/constants.ts
|
|
43
|
+
/**
|
|
44
|
+
* Default values for all `Options` fields.
|
|
45
|
+
*/
|
|
46
|
+
const DEFAULT_PARSER_OPTIONS = {
|
|
47
|
+
dateType: "string",
|
|
48
|
+
integerType: "number",
|
|
49
|
+
unknownType: "any",
|
|
50
|
+
emptySchemaType: "any",
|
|
51
|
+
enumSuffix: "enum"
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* OpenAPI version string written into merged document stubs.
|
|
55
|
+
*/
|
|
56
|
+
const MERGE_OPENAPI_VERSION = "3.0.0";
|
|
57
|
+
/**
|
|
58
|
+
* Fallback `info.title` used when merging multiple API documents.
|
|
59
|
+
*/
|
|
60
|
+
const MERGE_DEFAULT_TITLE = "Merged API";
|
|
61
|
+
/**
|
|
62
|
+
* Fallback `info.version` used when merging multiple API documents.
|
|
63
|
+
*/
|
|
64
|
+
const MERGE_DEFAULT_VERSION = "1.0.0";
|
|
65
|
+
/**
|
|
66
|
+
* JSON Schema keywords that indicate structural composition.
|
|
67
|
+
* A schema fragment containing any of these keys must not be inlined into its
|
|
68
|
+
* parent during `allOf` flattening — it carries semantic meaning of its own.
|
|
69
|
+
*/
|
|
70
|
+
const structuralKeys = new Set([
|
|
71
|
+
"properties",
|
|
72
|
+
"items",
|
|
73
|
+
"additionalProperties",
|
|
74
|
+
"oneOf",
|
|
75
|
+
"anyOf",
|
|
76
|
+
"allOf",
|
|
77
|
+
"not"
|
|
78
|
+
]);
|
|
79
|
+
/**
|
|
80
|
+
* Maps OAS/JSON Schema `format` strings to their Kubb `SchemaType` equivalents.
|
|
81
|
+
*
|
|
82
|
+
* Only formats that need a type different from the raw OAS `type` are listed.
|
|
83
|
+
* `int64`, `date-time`, `date`, and `time` are handled separately because their
|
|
84
|
+
* mapping depends on runtime parser options.
|
|
85
|
+
*
|
|
86
|
+
* Note: `ipv4`, `ipv6`, and `hostname` map to `'url'` — the closest supported
|
|
87
|
+
* scalar type in the Kubb AST, even though these are not strictly URLs.
|
|
88
|
+
*/
|
|
89
|
+
const formatMap = {
|
|
90
|
+
uuid: "uuid",
|
|
91
|
+
email: "email",
|
|
92
|
+
"idn-email": "email",
|
|
93
|
+
uri: "url",
|
|
94
|
+
"uri-reference": "url",
|
|
95
|
+
url: "url",
|
|
96
|
+
ipv4: "url",
|
|
97
|
+
ipv6: "url",
|
|
98
|
+
hostname: "url",
|
|
99
|
+
"idn-hostname": "url",
|
|
100
|
+
binary: "blob",
|
|
101
|
+
byte: "blob",
|
|
102
|
+
int32: "integer",
|
|
103
|
+
float: "number",
|
|
104
|
+
double: "number"
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Exhaustive list of media types that Kubb recognizes.
|
|
108
|
+
*/
|
|
109
|
+
const knownMediaTypes = new Set([
|
|
110
|
+
"application/json",
|
|
111
|
+
"application/xml",
|
|
112
|
+
"application/x-www-form-urlencoded",
|
|
113
|
+
"application/octet-stream",
|
|
114
|
+
"application/pdf",
|
|
115
|
+
"application/zip",
|
|
116
|
+
"application/graphql",
|
|
117
|
+
"multipart/form-data",
|
|
118
|
+
"text/plain",
|
|
119
|
+
"text/html",
|
|
120
|
+
"text/csv",
|
|
121
|
+
"text/xml",
|
|
122
|
+
"image/png",
|
|
123
|
+
"image/jpeg",
|
|
124
|
+
"image/gif",
|
|
125
|
+
"image/webp",
|
|
126
|
+
"image/svg+xml",
|
|
127
|
+
"audio/mpeg",
|
|
128
|
+
"video/mp4"
|
|
129
|
+
]);
|
|
130
|
+
/**
|
|
131
|
+
* Vendor extension keys used to attach human-readable labels to enum values.
|
|
132
|
+
* Checked in priority order: the first key found wins.
|
|
133
|
+
*/
|
|
134
|
+
const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
135
|
+
/**
|
|
136
|
+
* Scalar primitive schema types used for union member simplification.
|
|
137
|
+
*/
|
|
138
|
+
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
139
|
+
"string",
|
|
140
|
+
"number",
|
|
141
|
+
"integer",
|
|
142
|
+
"bigint",
|
|
143
|
+
"boolean"
|
|
144
|
+
]);
|
|
145
|
+
//#endregion
|
|
42
146
|
//#region src/oas/resolveServerUrl.ts
|
|
43
147
|
/**
|
|
44
148
|
* Resolves an OpenAPI server URL by substituting `{variable}` placeholders.
|
|
@@ -117,6 +221,27 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
117
221
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
118
222
|
}
|
|
119
223
|
//#endregion
|
|
224
|
+
//#region ../../internals/utils/src/names.ts
|
|
225
|
+
/**
|
|
226
|
+
* Returns a unique name by appending an incrementing numeric suffix when the name has already been used.
|
|
227
|
+
* Mutates `data` in-place as a usage counter so subsequent calls remain consistent.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* const seen: Record<string, number> = {}
|
|
231
|
+
* getUniqueName('Foo', seen) // 'Foo'
|
|
232
|
+
* getUniqueName('Foo', seen) // 'Foo2'
|
|
233
|
+
* getUniqueName('Foo', seen) // 'Foo3'
|
|
234
|
+
*/
|
|
235
|
+
function getUniqueName(originalName, data) {
|
|
236
|
+
let used = data[originalName] || 0;
|
|
237
|
+
if (used) {
|
|
238
|
+
data[originalName] = ++used;
|
|
239
|
+
originalName += used;
|
|
240
|
+
}
|
|
241
|
+
data[originalName] = 1;
|
|
242
|
+
return originalName;
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
120
245
|
//#region ../../internals/utils/src/reserved.ts
|
|
121
246
|
/**
|
|
122
247
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
@@ -233,100 +358,6 @@ var URLPath = class {
|
|
|
233
358
|
}
|
|
234
359
|
};
|
|
235
360
|
//#endregion
|
|
236
|
-
//#region src/constants.ts
|
|
237
|
-
/**
|
|
238
|
-
* OpenAPI version string written into merged document stubs.
|
|
239
|
-
*/
|
|
240
|
-
const MERGE_OPENAPI_VERSION = "3.0.0";
|
|
241
|
-
/**
|
|
242
|
-
* Fallback `info.title` used when merging multiple API documents.
|
|
243
|
-
*/
|
|
244
|
-
const MERGE_DEFAULT_TITLE = "Merged API";
|
|
245
|
-
/**
|
|
246
|
-
* Fallback `info.version` used when merging multiple API documents.
|
|
247
|
-
*/
|
|
248
|
-
const MERGE_DEFAULT_VERSION = "1.0.0";
|
|
249
|
-
/**
|
|
250
|
-
* JSON Schema keywords that indicate structural composition.
|
|
251
|
-
* A schema fragment containing any of these keys must not be inlined into its
|
|
252
|
-
* parent during `allOf` flattening — it carries semantic meaning of its own.
|
|
253
|
-
*/
|
|
254
|
-
const structuralKeys = new Set([
|
|
255
|
-
"properties",
|
|
256
|
-
"items",
|
|
257
|
-
"additionalProperties",
|
|
258
|
-
"oneOf",
|
|
259
|
-
"anyOf",
|
|
260
|
-
"allOf",
|
|
261
|
-
"not"
|
|
262
|
-
]);
|
|
263
|
-
/**
|
|
264
|
-
* Maps OAS/JSON Schema `format` strings to their Kubb `SchemaType` equivalents.
|
|
265
|
-
*
|
|
266
|
-
* Only formats that need a type different from the raw OAS `type` are listed.
|
|
267
|
-
* `int64`, `date-time`, `date`, and `time` are handled separately because their
|
|
268
|
-
* mapping depends on runtime parser options.
|
|
269
|
-
*
|
|
270
|
-
* Note: `ipv4`, `ipv6`, and `hostname` map to `'url'` — the closest supported
|
|
271
|
-
* scalar type in the Kubb AST, even though these are not strictly URLs.
|
|
272
|
-
*/
|
|
273
|
-
const formatMap = {
|
|
274
|
-
uuid: "uuid",
|
|
275
|
-
email: "email",
|
|
276
|
-
"idn-email": "email",
|
|
277
|
-
uri: "url",
|
|
278
|
-
"uri-reference": "url",
|
|
279
|
-
url: "url",
|
|
280
|
-
ipv4: "url",
|
|
281
|
-
ipv6: "url",
|
|
282
|
-
hostname: "url",
|
|
283
|
-
"idn-hostname": "url",
|
|
284
|
-
binary: "blob",
|
|
285
|
-
byte: "blob",
|
|
286
|
-
int32: "integer",
|
|
287
|
-
float: "number",
|
|
288
|
-
double: "number"
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Exhaustive list of media types that Kubb recognizes.
|
|
292
|
-
*/
|
|
293
|
-
const knownMediaTypes = new Set([
|
|
294
|
-
"application/json",
|
|
295
|
-
"application/xml",
|
|
296
|
-
"application/x-www-form-urlencoded",
|
|
297
|
-
"application/octet-stream",
|
|
298
|
-
"application/pdf",
|
|
299
|
-
"application/zip",
|
|
300
|
-
"application/graphql",
|
|
301
|
-
"multipart/form-data",
|
|
302
|
-
"text/plain",
|
|
303
|
-
"text/html",
|
|
304
|
-
"text/csv",
|
|
305
|
-
"text/xml",
|
|
306
|
-
"image/png",
|
|
307
|
-
"image/jpeg",
|
|
308
|
-
"image/gif",
|
|
309
|
-
"image/webp",
|
|
310
|
-
"image/svg+xml",
|
|
311
|
-
"audio/mpeg",
|
|
312
|
-
"video/mp4"
|
|
313
|
-
]);
|
|
314
|
-
/**
|
|
315
|
-
* Vendor extension keys used to attach human-readable labels to enum values.
|
|
316
|
-
* Checked in priority order: the first key found wins.
|
|
317
|
-
*/
|
|
318
|
-
const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
319
|
-
/**
|
|
320
|
-
* Scalar primitive schema types used for union member simplification.
|
|
321
|
-
*/
|
|
322
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
323
|
-
"string",
|
|
324
|
-
"number",
|
|
325
|
-
"integer",
|
|
326
|
-
"bigint",
|
|
327
|
-
"boolean"
|
|
328
|
-
]);
|
|
329
|
-
//#endregion
|
|
330
361
|
//#region src/oas/Oas.ts
|
|
331
362
|
/**
|
|
332
363
|
* Prefix used to create synthetic `$ref` values for anonymous (inline) discriminator schemas.
|
|
@@ -1080,16 +1111,6 @@ function getImports({ node, nameMapping, resolve }) {
|
|
|
1080
1111
|
//#endregion
|
|
1081
1112
|
//#region src/parser.ts
|
|
1082
1113
|
/**
|
|
1083
|
-
* Default values for all `Options` fields.
|
|
1084
|
-
*/
|
|
1085
|
-
const DEFAULT_OPTIONS = {
|
|
1086
|
-
dateType: "string",
|
|
1087
|
-
integerType: "number",
|
|
1088
|
-
unknownType: "any",
|
|
1089
|
-
emptySchemaType: "any",
|
|
1090
|
-
enumSuffix: "enum"
|
|
1091
|
-
};
|
|
1092
|
-
/**
|
|
1093
1114
|
* Looks up the Kubb `SchemaType` for a given OAS `format` string.
|
|
1094
1115
|
* Returns `undefined` for formats not in `formatMap` (e.g. `int64`, `date-time`),
|
|
1095
1116
|
* which are handled separately because their output depends on parser options.
|
|
@@ -1138,6 +1159,8 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1138
1159
|
contentType,
|
|
1139
1160
|
collisionDetection
|
|
1140
1161
|
});
|
|
1162
|
+
const usedEnumNames = {};
|
|
1163
|
+
const isLegacyNaming = collisionDetection === false;
|
|
1141
1164
|
/**
|
|
1142
1165
|
* Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
|
|
1143
1166
|
* Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
|
|
@@ -1184,7 +1207,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1184
1207
|
* Shared metadata fields included in every `createSchema` call.
|
|
1185
1208
|
* Centralizes the common properties so sub-handlers don't repeat them.
|
|
1186
1209
|
*/
|
|
1187
|
-
function
|
|
1210
|
+
function renderSchemaBase(schema, name, nullable, defaultValue) {
|
|
1188
1211
|
return {
|
|
1189
1212
|
name,
|
|
1190
1213
|
nullable,
|
|
@@ -1292,7 +1315,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1292
1315
|
return (0, _kubb_ast.createSchema)({
|
|
1293
1316
|
type: "intersection",
|
|
1294
1317
|
members: [...allOfMembers.slice(0, syntheticStart), ...mergeAdjacentAnonymousObjects(allOfMembers.slice(syntheticStart))],
|
|
1295
|
-
...
|
|
1318
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1296
1319
|
});
|
|
1297
1320
|
}
|
|
1298
1321
|
/**
|
|
@@ -1306,23 +1329,23 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1306
1329
|
function convertUnion({ schema, name, nullable, defaultValue, options }) {
|
|
1307
1330
|
const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
|
|
1308
1331
|
const unionBase = {
|
|
1309
|
-
...
|
|
1332
|
+
...renderSchemaBase(schema, name, nullable, defaultValue),
|
|
1310
1333
|
discriminatorPropertyName: isDiscriminator(schema) ? schema.discriminator.propertyName : void 0
|
|
1311
1334
|
};
|
|
1312
1335
|
if (schema.properties) {
|
|
1313
1336
|
const { oneOf: _oneOf, anyOf: _anyOf, ...schemaWithoutUnion } = schema;
|
|
1314
1337
|
const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
|
|
1315
|
-
const
|
|
1338
|
+
const sharedPropertiesNode = convertSchema({
|
|
1339
|
+
schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
|
|
1340
|
+
name: isLegacyNaming ? void 0 : name
|
|
1341
|
+
}, options);
|
|
1316
1342
|
return (0, _kubb_ast.createSchema)({
|
|
1317
1343
|
type: "union",
|
|
1318
1344
|
...unionBase,
|
|
1319
1345
|
members: unionMembers.map((s) => {
|
|
1320
1346
|
const ref = isReference(s) ? s.$ref : void 0;
|
|
1321
1347
|
const discriminatorValue = discriminator?.mapping && ref ? Object.entries(discriminator.mapping).find(([, v]) => v === ref)?.[0] : void 0;
|
|
1322
|
-
let propertiesNode =
|
|
1323
|
-
schema: memberBaseSchema,
|
|
1324
|
-
name
|
|
1325
|
-
}, options);
|
|
1348
|
+
let propertiesNode = sharedPropertiesNode;
|
|
1326
1349
|
if (discriminatorValue && discriminator) propertiesNode = applyDiscriminatorEnum({
|
|
1327
1350
|
node: propertiesNode,
|
|
1328
1351
|
propertyName: discriminator.propertyName,
|
|
@@ -1361,7 +1384,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1361
1384
|
type: "enum",
|
|
1362
1385
|
primitive: getPrimitiveType(typeof constValue === "number" ? "number" : typeof constValue === "boolean" ? "boolean" : "string"),
|
|
1363
1386
|
enumValues: [constValue],
|
|
1364
|
-
...
|
|
1387
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1365
1388
|
});
|
|
1366
1389
|
}
|
|
1367
1390
|
/**
|
|
@@ -1370,7 +1393,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1370
1393
|
* (i.e. `format: 'date-time'` with `dateType: false`).
|
|
1371
1394
|
*/
|
|
1372
1395
|
function convertFormat({ schema, name, nullable, defaultValue, mergedOptions }) {
|
|
1373
|
-
const base =
|
|
1396
|
+
const base = renderSchemaBase(schema, name, nullable, defaultValue);
|
|
1374
1397
|
if (schema.format === "int64") return (0, _kubb_ast.createSchema)({
|
|
1375
1398
|
type: mergedOptions.integerType === "bigint" ? "bigint" : "integer",
|
|
1376
1399
|
primitive: "integer",
|
|
@@ -1508,29 +1531,62 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1508
1531
|
* - not required + not nullable → `optional: true`
|
|
1509
1532
|
* - not required + nullable → `nullish: true`
|
|
1510
1533
|
*/
|
|
1534
|
+
/**
|
|
1535
|
+
* Builds the propagation name for a child property during recursive schema conversion.
|
|
1536
|
+
*
|
|
1537
|
+
* - **Legacy naming** (`isLegacyNaming`): only the immediate property key is used
|
|
1538
|
+
* (e.g. `Params` for property `params`), keeping nested names short.
|
|
1539
|
+
* - **Default naming**: the parent name is prepended so the full path is encoded
|
|
1540
|
+
* (e.g. `OrderParams` when parent is `Order`).
|
|
1541
|
+
*/
|
|
1542
|
+
function resolveChildName(parentName, propName) {
|
|
1543
|
+
if (isLegacyNaming) return pascalCase(propName);
|
|
1544
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
|
|
1545
|
+
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Derives the final name for an enum property schema node.
|
|
1548
|
+
*
|
|
1549
|
+
* The raw name always includes the enum suffix (e.g. `StatusEnum`).
|
|
1550
|
+
* In legacy mode an additional deduplication step appends a numeric suffix
|
|
1551
|
+
* when the same name has already been used (e.g. `ParamsStatusEnum2`).
|
|
1552
|
+
*/
|
|
1553
|
+
function resolveEnumPropName(parentName, propName, enumSuffix) {
|
|
1554
|
+
const raw = pascalCase([
|
|
1555
|
+
parentName,
|
|
1556
|
+
propName,
|
|
1557
|
+
enumSuffix
|
|
1558
|
+
].filter(Boolean).join(" "));
|
|
1559
|
+
return isLegacyNaming ? getUniqueName(raw, usedEnumNames) : raw;
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Given a freshly-converted property schema, returns the node with a correct
|
|
1563
|
+
* `name` attached — or stripped — depending on whether the node is a named
|
|
1564
|
+
* enum, a boolean const-enum (always inlined), or a regular schema.
|
|
1565
|
+
*/
|
|
1566
|
+
function applyEnumName(propNode, parentName, propName, enumSuffix) {
|
|
1567
|
+
const enumNode = (0, _kubb_ast.narrowSchema)(propNode, "enum");
|
|
1568
|
+
if (enumNode?.primitive === "boolean") return {
|
|
1569
|
+
...propNode,
|
|
1570
|
+
name: void 0
|
|
1571
|
+
};
|
|
1572
|
+
if (enumNode) return {
|
|
1573
|
+
...propNode,
|
|
1574
|
+
name: resolveEnumPropName(parentName, propName, enumSuffix)
|
|
1575
|
+
};
|
|
1576
|
+
return propNode;
|
|
1577
|
+
}
|
|
1511
1578
|
function convertObject({ schema, name, nullable, defaultValue, options, mergedOptions }) {
|
|
1512
1579
|
const properties = schema.properties ? Object.entries(schema.properties).map(([propName, propSchema]) => {
|
|
1513
1580
|
const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
|
|
1514
1581
|
const resolvedPropSchema = propSchema;
|
|
1515
1582
|
const propNullable = isNullable(resolvedPropSchema);
|
|
1516
|
-
const basePropName = name ? pascalCase([name, propName].join(" ")) : void 0;
|
|
1517
|
-
const propNode = convertSchema({
|
|
1518
|
-
schema: resolvedPropSchema,
|
|
1519
|
-
name: basePropName
|
|
1520
|
-
}, options);
|
|
1521
|
-
const isEnumNode = !!(0, _kubb_ast.narrowSchema)(propNode, "enum");
|
|
1522
|
-
const derivedPropName = isEnumNode && name ? pascalCase([
|
|
1523
|
-
name,
|
|
1524
|
-
propName,
|
|
1525
|
-
mergedOptions.enumSuffix
|
|
1526
|
-
].filter(Boolean).join(" ")) : basePropName;
|
|
1527
1583
|
return (0, _kubb_ast.createProperty)({
|
|
1528
1584
|
name: propName,
|
|
1529
1585
|
schema: {
|
|
1530
|
-
...
|
|
1531
|
-
|
|
1532
|
-
name:
|
|
1533
|
-
}
|
|
1586
|
+
...applyEnumName(convertSchema({
|
|
1587
|
+
schema: resolvedPropSchema,
|
|
1588
|
+
name: resolveChildName(name, propName)
|
|
1589
|
+
}, options), name, propName, mergedOptions.enumSuffix),
|
|
1534
1590
|
nullable: propNullable || void 0,
|
|
1535
1591
|
optional: !required && !propNullable ? true : void 0,
|
|
1536
1592
|
nullish: !required && propNullable ? true : void 0
|
|
@@ -1552,7 +1608,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1552
1608
|
properties,
|
|
1553
1609
|
additionalProperties: additionalPropertiesNode,
|
|
1554
1610
|
patternProperties,
|
|
1555
|
-
...
|
|
1611
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1556
1612
|
});
|
|
1557
1613
|
if (isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
1558
1614
|
const discPropName = schema.discriminator.propertyName;
|
|
@@ -1560,11 +1616,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1560
1616
|
node: objectNode,
|
|
1561
1617
|
propertyName: discPropName,
|
|
1562
1618
|
values: Object.keys(schema.discriminator.mapping),
|
|
1563
|
-
enumName: name ?
|
|
1564
|
-
name,
|
|
1565
|
-
discPropName,
|
|
1566
|
-
mergedOptions.enumSuffix
|
|
1567
|
-
].filter(Boolean).join(" ")) : void 0
|
|
1619
|
+
enumName: name ? resolveEnumPropName(name, discPropName, mergedOptions.enumSuffix) : void 0
|
|
1568
1620
|
});
|
|
1569
1621
|
}
|
|
1570
1622
|
return objectNode;
|
|
@@ -1583,7 +1635,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1583
1635
|
rest: schema.items ? convertSchema({ schema: schema.items }, options) : void 0,
|
|
1584
1636
|
min: schema.minItems,
|
|
1585
1637
|
max: schema.maxItems,
|
|
1586
|
-
...
|
|
1638
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1587
1639
|
});
|
|
1588
1640
|
}
|
|
1589
1641
|
/**
|
|
@@ -1594,7 +1646,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1594
1646
|
*/
|
|
1595
1647
|
function convertArray({ schema, name, nullable, defaultValue, options, mergedOptions }) {
|
|
1596
1648
|
const rawItems = schema.items;
|
|
1597
|
-
const itemName = rawItems?.enum?.length && name ?
|
|
1649
|
+
const itemName = rawItems?.enum?.length && name ? resolveEnumPropName(void 0, name, mergedOptions.enumSuffix) : void 0;
|
|
1598
1650
|
return (0, _kubb_ast.createSchema)({
|
|
1599
1651
|
type: "array",
|
|
1600
1652
|
primitive: "array",
|
|
@@ -1605,7 +1657,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1605
1657
|
min: schema.minItems,
|
|
1606
1658
|
max: schema.maxItems,
|
|
1607
1659
|
unique: schema.uniqueItems ?? void 0,
|
|
1608
|
-
...
|
|
1660
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1609
1661
|
});
|
|
1610
1662
|
}
|
|
1611
1663
|
/**
|
|
@@ -1618,7 +1670,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1618
1670
|
min: schema.minLength,
|
|
1619
1671
|
max: schema.maxLength,
|
|
1620
1672
|
pattern: schema.pattern,
|
|
1621
|
-
...
|
|
1673
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1622
1674
|
});
|
|
1623
1675
|
}
|
|
1624
1676
|
/**
|
|
@@ -1632,7 +1684,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1632
1684
|
max: schema.maximum,
|
|
1633
1685
|
exclusiveMinimum: typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum : void 0,
|
|
1634
1686
|
exclusiveMaximum: typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : void 0,
|
|
1635
|
-
...
|
|
1687
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1636
1688
|
});
|
|
1637
1689
|
}
|
|
1638
1690
|
/**
|
|
@@ -1642,7 +1694,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1642
1694
|
return (0, _kubb_ast.createSchema)({
|
|
1643
1695
|
type: "boolean",
|
|
1644
1696
|
primitive: "boolean",
|
|
1645
|
-
...
|
|
1697
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1646
1698
|
});
|
|
1647
1699
|
}
|
|
1648
1700
|
/**
|
|
@@ -1677,7 +1729,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1677
1729
|
*/
|
|
1678
1730
|
function convertSchema({ schema, name }, options) {
|
|
1679
1731
|
const mergedOptions = {
|
|
1680
|
-
...
|
|
1732
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
1681
1733
|
...options
|
|
1682
1734
|
};
|
|
1683
1735
|
const flattenedSchema = flattenSchema(schema);
|
|
@@ -1708,7 +1760,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1708
1760
|
if (schema.type === "string" && schema.contentMediaType === "application/octet-stream") return (0, _kubb_ast.createSchema)({
|
|
1709
1761
|
type: "blob",
|
|
1710
1762
|
primitive: "string",
|
|
1711
|
-
...
|
|
1763
|
+
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1712
1764
|
});
|
|
1713
1765
|
if (Array.isArray(schema.type) && schema.type.length > 1) {
|
|
1714
1766
|
const nonNullTypes = schema.type.filter((t) => t !== "null");
|
|
@@ -1722,7 +1774,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1722
1774
|
},
|
|
1723
1775
|
name
|
|
1724
1776
|
}, options)),
|
|
1725
|
-
...
|
|
1777
|
+
...renderSchemaBase(schema, name, arrayNullable, defaultValue)
|
|
1726
1778
|
});
|
|
1727
1779
|
}
|
|
1728
1780
|
if (!type) {
|
|
@@ -1803,7 +1855,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1803
1855
|
*/
|
|
1804
1856
|
function parse(options) {
|
|
1805
1857
|
const mergedOptions = {
|
|
1806
|
-
...
|
|
1858
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
1807
1859
|
...options
|
|
1808
1860
|
};
|
|
1809
1861
|
const schemas = Object.entries(schemaObjects).map(([name, schemaObject]) => convertSchema({
|
|
@@ -1873,7 +1925,7 @@ const adapterOasName = "oas";
|
|
|
1873
1925
|
* ```
|
|
1874
1926
|
*/
|
|
1875
1927
|
const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
1876
|
-
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection =
|
|
1928
|
+
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = true, dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType } = options;
|
|
1877
1929
|
const nameMapping = /* @__PURE__ */ new Map();
|
|
1878
1930
|
return {
|
|
1879
1931
|
name: "oas",
|
|
@@ -1889,6 +1941,7 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
1889
1941
|
integerType,
|
|
1890
1942
|
unknownType,
|
|
1891
1943
|
emptySchemaType,
|
|
1944
|
+
enumSuffix,
|
|
1892
1945
|
nameMapping
|
|
1893
1946
|
},
|
|
1894
1947
|
getImports(node, resolve) {
|
|
@@ -1921,7 +1974,8 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
1921
1974
|
dateType,
|
|
1922
1975
|
integerType,
|
|
1923
1976
|
unknownType,
|
|
1924
|
-
emptySchemaType
|
|
1977
|
+
emptySchemaType,
|
|
1978
|
+
enumSuffix
|
|
1925
1979
|
}),
|
|
1926
1980
|
meta: {
|
|
1927
1981
|
title: oas.api.info?.title,
|