@kubb/adapter-oas 5.0.0-alpha.24 → 5.0.0-alpha.26
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 +54 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/constants.ts +4 -3
- package/src/factory.ts +4 -1
- package/src/parser.ts +44 -12
package/dist/index.cjs
CHANGED
|
@@ -98,7 +98,8 @@ const structuralKeys = new Set([
|
|
|
98
98
|
*
|
|
99
99
|
* Only formats whose AST type differs from the OAS `type` field appear here.
|
|
100
100
|
* Formats that depend on runtime options (`int64`, `date-time`, `date`, `time`) are handled separately
|
|
101
|
-
* in the parser. `ipv4
|
|
101
|
+
* in the parser. `ipv4` and `ipv6` map to their own dedicated schema types; `hostname` and
|
|
102
|
+
* `idn-hostname` map to `'url'` as the closest generic string-format type.
|
|
102
103
|
*
|
|
103
104
|
* @example
|
|
104
105
|
* ```ts
|
|
@@ -116,8 +117,8 @@ const formatMap = {
|
|
|
116
117
|
uri: "url",
|
|
117
118
|
"uri-reference": "url",
|
|
118
119
|
url: "url",
|
|
119
|
-
ipv4: "
|
|
120
|
-
ipv6: "
|
|
120
|
+
ipv4: "ipv4",
|
|
121
|
+
ipv6: "ipv6",
|
|
121
122
|
hostname: "url",
|
|
122
123
|
"idn-hostname": "url",
|
|
123
124
|
binary: "blob",
|
|
@@ -556,10 +557,11 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
|
|
|
556
557
|
* ```
|
|
557
558
|
*/
|
|
558
559
|
async function mergeDocuments(pathOrApi) {
|
|
559
|
-
const documents =
|
|
560
|
+
const documents = [];
|
|
561
|
+
for (const p of pathOrApi) documents.push(await parseDocument(p, {
|
|
560
562
|
enablePaths: false,
|
|
561
563
|
canBundle: false
|
|
562
|
-
}))
|
|
564
|
+
}));
|
|
563
565
|
if (documents.length === 0) throw new Error("No OAS documents provided for merging.");
|
|
564
566
|
const seed = {
|
|
565
567
|
openapi: MERGE_OPENAPI_VERSION,
|
|
@@ -1025,21 +1027,35 @@ function normalizeArrayEnum(schema) {
|
|
|
1025
1027
|
function createSchemaParser(ctx) {
|
|
1026
1028
|
const document = ctx.document;
|
|
1027
1029
|
/**
|
|
1030
|
+
* Tracks `$ref` paths that are currently being resolved to prevent infinite
|
|
1031
|
+
* recursion when schemas contain circular references (e.g. `Pet → parent → Pet`).
|
|
1032
|
+
*/
|
|
1033
|
+
const resolvingRefs = /* @__PURE__ */ new Set();
|
|
1034
|
+
/**
|
|
1028
1035
|
* Converts a `$ref` schema into a `RefSchemaNode`.
|
|
1036
|
+
*
|
|
1037
|
+
* The resolved schema is stored in `node.schema`. Usage-site sibling fields
|
|
1038
|
+
* (description, readOnly, nullable, etc.) are stored directly on the ref node.
|
|
1039
|
+
* Use `syncSchemaRef(node)` in printers to get a merged view of both.
|
|
1040
|
+
* Circular refs are detected via `resolvingRefs` and leave `schema` as `undefined`.
|
|
1029
1041
|
*/
|
|
1030
|
-
function convertRef({ schema, nullable, defaultValue }) {
|
|
1042
|
+
function convertRef({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1043
|
+
let resolvedSchema;
|
|
1044
|
+
const refPath = schema.$ref;
|
|
1045
|
+
if (refPath && !resolvingRefs.has(refPath)) try {
|
|
1046
|
+
const referenced = resolveRef(document, refPath);
|
|
1047
|
+
if (referenced) {
|
|
1048
|
+
resolvingRefs.add(refPath);
|
|
1049
|
+
resolvedSchema = parseSchema({ schema: referenced }, rawOptions);
|
|
1050
|
+
resolvingRefs.delete(refPath);
|
|
1051
|
+
}
|
|
1052
|
+
} catch {}
|
|
1031
1053
|
return (0, _kubb_ast.createSchema)({
|
|
1054
|
+
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1032
1055
|
type: "ref",
|
|
1033
1056
|
name: (0, _kubb_ast.extractRefName)(schema.$ref),
|
|
1034
1057
|
ref: schema.$ref,
|
|
1035
|
-
|
|
1036
|
-
description: schema.description,
|
|
1037
|
-
deprecated: schema.deprecated,
|
|
1038
|
-
readOnly: schema.readOnly,
|
|
1039
|
-
writeOnly: schema.writeOnly,
|
|
1040
|
-
pattern: schema.type === "string" ? schema.pattern : void 0,
|
|
1041
|
-
example: schema.example,
|
|
1042
|
-
default: defaultValue
|
|
1058
|
+
schema: resolvedSchema
|
|
1043
1059
|
});
|
|
1044
1060
|
}
|
|
1045
1061
|
/**
|
|
@@ -1247,7 +1263,26 @@ function createSchemaParser(ctx) {
|
|
|
1247
1263
|
if (specialType === "url") return (0, _kubb_ast.createSchema)({
|
|
1248
1264
|
...base,
|
|
1249
1265
|
primitive: "string",
|
|
1250
|
-
type: "url"
|
|
1266
|
+
type: "url",
|
|
1267
|
+
min: schema.minLength,
|
|
1268
|
+
max: schema.maxLength
|
|
1269
|
+
});
|
|
1270
|
+
if (specialType === "ipv4") return (0, _kubb_ast.createSchema)({
|
|
1271
|
+
...base,
|
|
1272
|
+
primitive: "string",
|
|
1273
|
+
type: "ipv4"
|
|
1274
|
+
});
|
|
1275
|
+
if (specialType === "ipv6") return (0, _kubb_ast.createSchema)({
|
|
1276
|
+
...base,
|
|
1277
|
+
primitive: "string",
|
|
1278
|
+
type: "ipv6"
|
|
1279
|
+
});
|
|
1280
|
+
if (specialType === "uuid" || specialType === "email") return (0, _kubb_ast.createSchema)({
|
|
1281
|
+
...base,
|
|
1282
|
+
primitive: "string",
|
|
1283
|
+
type: specialType,
|
|
1284
|
+
min: schema.minLength,
|
|
1285
|
+
max: schema.maxLength
|
|
1251
1286
|
});
|
|
1252
1287
|
return (0, _kubb_ast.createSchema)({
|
|
1253
1288
|
...base,
|
|
@@ -1333,7 +1368,7 @@ function createSchemaParser(ctx) {
|
|
|
1333
1368
|
let additionalPropertiesNode;
|
|
1334
1369
|
if (additionalProperties === true) additionalPropertiesNode = true;
|
|
1335
1370
|
else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = parseSchema({ schema: additionalProperties }, rawOptions);
|
|
1336
|
-
else if (additionalProperties === false) additionalPropertiesNode =
|
|
1371
|
+
else if (additionalProperties === false) additionalPropertiesNode = false;
|
|
1337
1372
|
else if (additionalProperties) additionalPropertiesNode = (0, _kubb_ast.createSchema)({ type: typeOptionMap.get(options.unknownType) });
|
|
1338
1373
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
1339
1374
|
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? (0, _kubb_ast.createSchema)({ type: typeOptionMap.get(options.unknownType) }) : parseSchema({ schema: patternSchema }, rawOptions)])) : void 0;
|
|
@@ -1343,6 +1378,8 @@ function createSchemaParser(ctx) {
|
|
|
1343
1378
|
properties,
|
|
1344
1379
|
additionalProperties: additionalPropertiesNode,
|
|
1345
1380
|
patternProperties,
|
|
1381
|
+
minProperties: schema.minProperties,
|
|
1382
|
+
maxProperties: schema.maxProperties,
|
|
1346
1383
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1347
1384
|
});
|
|
1348
1385
|
if (isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
@@ -1413,6 +1450,7 @@ function createSchemaParser(ctx) {
|
|
|
1413
1450
|
max: schema.maximum,
|
|
1414
1451
|
exclusiveMinimum: typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum : void 0,
|
|
1415
1452
|
exclusiveMaximum: typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : void 0,
|
|
1453
|
+
multipleOf: schema.multipleOf,
|
|
1416
1454
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1417
1455
|
});
|
|
1418
1456
|
}
|