@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.js
CHANGED
|
@@ -960,21 +960,20 @@ function extractSchemaFromContent(content, preferredContentType) {
|
|
|
960
960
|
/**
|
|
961
961
|
* Walks a schema tree and collects the names of all `#/components/schemas/<name>` `$ref`s.
|
|
962
962
|
*/
|
|
963
|
-
function collectRefs(schema
|
|
963
|
+
function* collectRefs(schema) {
|
|
964
964
|
if (Array.isArray(schema)) {
|
|
965
|
-
for (const item of schema) collectRefs(item
|
|
966
|
-
return
|
|
965
|
+
for (const item of schema) yield* collectRefs(item);
|
|
966
|
+
return;
|
|
967
967
|
}
|
|
968
968
|
if (schema && typeof schema === "object") for (const key in schema) {
|
|
969
969
|
const value = schema[key];
|
|
970
970
|
if (key === "$ref" && typeof value === "string") {
|
|
971
971
|
if (value.startsWith("#/components/schemas/")) {
|
|
972
972
|
const name = value.slice(21);
|
|
973
|
-
if (name)
|
|
973
|
+
if (name) yield name;
|
|
974
974
|
}
|
|
975
|
-
} else collectRefs(value
|
|
975
|
+
} else yield* collectRefs(value);
|
|
976
976
|
}
|
|
977
|
-
return refs;
|
|
978
977
|
}
|
|
979
978
|
/**
|
|
980
979
|
* Returns a copy of `schemas` topologically sorted by `$ref` dependency.
|
|
@@ -990,7 +989,7 @@ function collectRefs(schema, refs = /* @__PURE__ */ new Set()) {
|
|
|
990
989
|
*/
|
|
991
990
|
function sortSchemas(schemas) {
|
|
992
991
|
const deps = /* @__PURE__ */ new Map();
|
|
993
|
-
for (const [name, schema] of Object.entries(schemas)) deps.set(name,
|
|
992
|
+
for (const [name, schema] of Object.entries(schemas)) deps.set(name, [...new Set(collectRefs(schema))]);
|
|
994
993
|
const sorted = [];
|
|
995
994
|
const visited = /* @__PURE__ */ new Set();
|
|
996
995
|
function visit(name, stack) {
|
|
@@ -1193,7 +1192,7 @@ function createSchemaParser(ctx) {
|
|
|
1193
1192
|
* blowup — `customer` alone may be referenced from dozens of top-level schemas,
|
|
1194
1193
|
* each triggering a fresh recursive expansion of its entire sub-tree.
|
|
1195
1194
|
*
|
|
1196
|
-
*
|
|
1195
|
+
* Memoizing by `$ref` path reduces the overall work from O(2^depth) to O(N)
|
|
1197
1196
|
* where N is the number of unique schema names.
|
|
1198
1197
|
*/
|
|
1199
1198
|
const resolvedRefCache = /* @__PURE__ */ new Map();
|
|
@@ -1304,7 +1303,7 @@ function createSchemaParser(ctx) {
|
|
|
1304
1303
|
}));
|
|
1305
1304
|
return ast.createSchema({
|
|
1306
1305
|
type: "intersection",
|
|
1307
|
-
members: [...ast.
|
|
1306
|
+
members: [...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))],
|
|
1308
1307
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1309
1308
|
});
|
|
1310
1309
|
}
|
|
@@ -1882,7 +1881,7 @@ function parseOas(document, options = {}) {
|
|
|
1882
1881
|
name
|
|
1883
1882
|
}, mergedOptions));
|
|
1884
1883
|
const paths = new BaseOas(document).getPaths();
|
|
1885
|
-
const operations = Object.entries(paths).flatMap(([
|
|
1884
|
+
const operations = Object.entries(paths).flatMap(([, methods]) => Object.entries(methods).map(([, operation]) => operation ? _parseOperation(mergedOptions, operation) : null).filter((op) => op !== null));
|
|
1886
1885
|
return {
|
|
1887
1886
|
root: ast.createInput({
|
|
1888
1887
|
schemas,
|