@kubb/adapter-oas 5.0.0-beta.13 → 5.0.0-beta.15
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 +9 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/parser.ts +3 -3
- package/src/resolvers.ts +6 -8
package/dist/index.cjs
CHANGED
|
@@ -986,21 +986,20 @@ function extractSchemaFromContent(content, preferredContentType) {
|
|
|
986
986
|
/**
|
|
987
987
|
* Walks a schema tree and collects the names of all `#/components/schemas/<name>` `$ref`s.
|
|
988
988
|
*/
|
|
989
|
-
function collectRefs(schema
|
|
989
|
+
function* collectRefs(schema) {
|
|
990
990
|
if (Array.isArray(schema)) {
|
|
991
|
-
for (const item of schema) collectRefs(item
|
|
992
|
-
return
|
|
991
|
+
for (const item of schema) yield* collectRefs(item);
|
|
992
|
+
return;
|
|
993
993
|
}
|
|
994
994
|
if (schema && typeof schema === "object") for (const key in schema) {
|
|
995
995
|
const value = schema[key];
|
|
996
996
|
if (key === "$ref" && typeof value === "string") {
|
|
997
997
|
if (value.startsWith("#/components/schemas/")) {
|
|
998
998
|
const name = value.slice(21);
|
|
999
|
-
if (name)
|
|
999
|
+
if (name) yield name;
|
|
1000
1000
|
}
|
|
1001
|
-
} else collectRefs(value
|
|
1001
|
+
} else yield* collectRefs(value);
|
|
1002
1002
|
}
|
|
1003
|
-
return refs;
|
|
1004
1003
|
}
|
|
1005
1004
|
/**
|
|
1006
1005
|
* Returns a copy of `schemas` topologically sorted by `$ref` dependency.
|
|
@@ -1016,7 +1015,7 @@ function collectRefs(schema, refs = /* @__PURE__ */ new Set()) {
|
|
|
1016
1015
|
*/
|
|
1017
1016
|
function sortSchemas(schemas) {
|
|
1018
1017
|
const deps = /* @__PURE__ */ new Map();
|
|
1019
|
-
for (const [name, schema] of Object.entries(schemas)) deps.set(name,
|
|
1018
|
+
for (const [name, schema] of Object.entries(schemas)) deps.set(name, [...new Set(collectRefs(schema))]);
|
|
1020
1019
|
const sorted = [];
|
|
1021
1020
|
const visited = /* @__PURE__ */ new Set();
|
|
1022
1021
|
function visit(name, stack) {
|
|
@@ -1219,7 +1218,7 @@ function createSchemaParser(ctx) {
|
|
|
1219
1218
|
* blowup — `customer` alone may be referenced from dozens of top-level schemas,
|
|
1220
1219
|
* each triggering a fresh recursive expansion of its entire sub-tree.
|
|
1221
1220
|
*
|
|
1222
|
-
*
|
|
1221
|
+
* Memoizing by `$ref` path reduces the overall work from O(2^depth) to O(N)
|
|
1223
1222
|
* where N is the number of unique schema names.
|
|
1224
1223
|
*/
|
|
1225
1224
|
const resolvedRefCache = /* @__PURE__ */ new Map();
|
|
@@ -1330,7 +1329,7 @@ function createSchemaParser(ctx) {
|
|
|
1330
1329
|
}));
|
|
1331
1330
|
return _kubb_core.ast.createSchema({
|
|
1332
1331
|
type: "intersection",
|
|
1333
|
-
members: [..._kubb_core.ast.
|
|
1332
|
+
members: [..._kubb_core.ast.mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ..._kubb_core.ast.mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))],
|
|
1334
1333
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1335
1334
|
});
|
|
1336
1335
|
}
|
|
@@ -1908,7 +1907,7 @@ function parseOas(document, options = {}) {
|
|
|
1908
1907
|
name
|
|
1909
1908
|
}, mergedOptions));
|
|
1910
1909
|
const paths = new oas.default(document).getPaths();
|
|
1911
|
-
const operations = Object.entries(paths).flatMap(([
|
|
1910
|
+
const operations = Object.entries(paths).flatMap(([, methods]) => Object.entries(methods).map(([, operation]) => operation ? _parseOperation(mergedOptions, operation) : null).filter((op) => op !== null));
|
|
1912
1911
|
return {
|
|
1913
1912
|
root: _kubb_core.ast.createInput({
|
|
1914
1913
|
schemas,
|