@kubb/adapter-oas 5.0.0-alpha.42 → 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 +50 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +332 -13
- package/dist/index.js +48 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- 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.cjs
CHANGED
|
@@ -25,17 +25,12 @@ let _kubb_core = require("@kubb/core");
|
|
|
25
25
|
let node_path = require("node:path");
|
|
26
26
|
node_path = __toESM(node_path, 1);
|
|
27
27
|
let _redocly_openapi_core = require("@redocly/openapi-core");
|
|
28
|
-
let _stoplight_yaml = require("@stoplight/yaml");
|
|
29
|
-
_stoplight_yaml = __toESM(_stoplight_yaml, 1);
|
|
30
28
|
let oas_normalize = require("oas-normalize");
|
|
31
29
|
oas_normalize = __toESM(oas_normalize, 1);
|
|
32
|
-
let remeda = require("remeda");
|
|
33
30
|
let swagger2openapi = require("swagger2openapi");
|
|
34
31
|
swagger2openapi = __toESM(swagger2openapi, 1);
|
|
35
32
|
let oas = require("oas");
|
|
36
33
|
oas = __toESM(oas, 1);
|
|
37
|
-
let jsonpointer = require("jsonpointer");
|
|
38
|
-
jsonpointer = __toESM(jsonpointer, 1);
|
|
39
34
|
let oas_types = require("oas/types");
|
|
40
35
|
let oas_utils = require("oas/utils");
|
|
41
36
|
//#region src/constants.ts
|
|
@@ -286,6 +281,40 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
286
281
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
287
282
|
}
|
|
288
283
|
//#endregion
|
|
284
|
+
//#region ../../internals/utils/src/object.ts
|
|
285
|
+
/**
|
|
286
|
+
* Returns `true` when `value` is a plain (non-null, non-array) object.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* isPlainObject({}) // true
|
|
291
|
+
* isPlainObject([]) // false
|
|
292
|
+
* isPlainObject(null) // false
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
function isPlainObject(value) {
|
|
296
|
+
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Recursively merges `source` into `target`, combining nested plain objects.
|
|
300
|
+
* Arrays and non-object values from `source` override the corresponding values in `target`.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* mergeDeep({ a: { x: 1 } }, { a: { y: 2 } })
|
|
305
|
+
* // { a: { x: 1, y: 2 } }
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
function mergeDeep(target, source) {
|
|
309
|
+
const result = { ...target };
|
|
310
|
+
for (const key of Object.keys(source)) {
|
|
311
|
+
const sv = source[key];
|
|
312
|
+
const tv = result[key];
|
|
313
|
+
result[key] = sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv) ? mergeDeep(tv, sv) : sv;
|
|
314
|
+
}
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
289
318
|
//#region ../../internals/utils/src/reserved.ts
|
|
290
319
|
/**
|
|
291
320
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
@@ -464,7 +493,7 @@ var URLPath = class {
|
|
|
464
493
|
* ```
|
|
465
494
|
*/
|
|
466
495
|
function isOpenApiV2Document(doc) {
|
|
467
|
-
return !!doc &&
|
|
496
|
+
return !!doc && isPlainObject(doc) && !("openapi" in doc);
|
|
468
497
|
}
|
|
469
498
|
/**
|
|
470
499
|
* Returns `true` when a schema should be treated as nullable.
|
|
@@ -548,7 +577,7 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
|
|
|
548
577
|
/**
|
|
549
578
|
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
550
579
|
*
|
|
551
|
-
* Each document is parsed independently then recursively merged
|
|
580
|
+
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
552
581
|
* Throws when the input array is empty.
|
|
553
582
|
*
|
|
554
583
|
* @example
|
|
@@ -572,7 +601,7 @@ async function mergeDocuments(pathOrApi) {
|
|
|
572
601
|
paths: {},
|
|
573
602
|
components: { schemas: {} }
|
|
574
603
|
};
|
|
575
|
-
return parseDocument(documents.reduce((acc, current) =>
|
|
604
|
+
return parseDocument(documents.reduce((acc, current) => mergeDeep(acc, current), seed));
|
|
576
605
|
}
|
|
577
606
|
/**
|
|
578
607
|
* Creates a `Document` from an `AdapterSource`.
|
|
@@ -591,11 +620,7 @@ async function mergeDocuments(pathOrApi) {
|
|
|
591
620
|
function parseFromConfig(source) {
|
|
592
621
|
if (source.type === "data") {
|
|
593
622
|
if (typeof source.data === "object") return parseDocument(structuredClone(source.data));
|
|
594
|
-
|
|
595
|
-
return parseDocument(_stoplight_yaml.default.parse(source.data));
|
|
596
|
-
} catch {
|
|
597
|
-
return parseDocument(source.data);
|
|
598
|
-
}
|
|
623
|
+
return parseDocument(source.data, { canBundle: false });
|
|
599
624
|
}
|
|
600
625
|
if (source.type === "paths") return mergeDocuments(source.paths);
|
|
601
626
|
if (new URLPath(source.path).isURL) return parseDocument(source.path);
|
|
@@ -638,7 +663,7 @@ function resolveRef(document, $ref) {
|
|
|
638
663
|
if ($ref === "") return null;
|
|
639
664
|
if ($ref.startsWith("#")) $ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
640
665
|
else return null;
|
|
641
|
-
const current =
|
|
666
|
+
const current = $ref.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
|
|
642
667
|
if (!current) throw new Error(`Could not find a definition for ${origRef}.`);
|
|
643
668
|
return current;
|
|
644
669
|
}
|
|
@@ -1323,15 +1348,21 @@ function createSchemaParser(ctx) {
|
|
|
1323
1348
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
1324
1349
|
if (extensionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1325
1350
|
const enumPrimitiveType = enumPrimitive === "number" || enumPrimitive === "integer" ? "number" : enumPrimitive === "boolean" ? "boolean" : "string";
|
|
1326
|
-
const
|
|
1351
|
+
const rawEnumNames = extensionKey ? schema[extensionKey] : void 0;
|
|
1352
|
+
const uniqueValues = [...new Set(filteredValues)];
|
|
1353
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1327
1354
|
return _kubb_core.ast.createSchema({
|
|
1328
1355
|
...enumBase,
|
|
1329
1356
|
primitive: enumPrimitiveType,
|
|
1330
|
-
namedEnumValues:
|
|
1331
|
-
name: String(
|
|
1332
|
-
value
|
|
1357
|
+
namedEnumValues: uniqueValues.map((value, index) => ({
|
|
1358
|
+
name: String(rawEnumNames?.[index] ?? value),
|
|
1359
|
+
value,
|
|
1333
1360
|
primitive: enumPrimitiveType
|
|
1334
|
-
}))
|
|
1361
|
+
})).filter((entry) => {
|
|
1362
|
+
if (seenNames.has(entry.name)) return false;
|
|
1363
|
+
seenNames.add(entry.name);
|
|
1364
|
+
return true;
|
|
1365
|
+
})
|
|
1335
1366
|
});
|
|
1336
1367
|
}
|
|
1337
1368
|
return _kubb_core.ast.createSchema({
|