Skip to content

Commit 319c700

Browse files
authored
Improve error in load.ts parsing (#1043)
1 parent bf162e7 commit 319c700

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/load.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,18 @@ export default async function load(
211211
for (const k of ["allOf", "anyOf", "oneOf"]) {
212212
if (Array.isArray(rawNode[k])) {
213213
rawNode[k] = (rawNode as any)[k].filter((o: SchemaObject | ReferenceObject) => {
214+
if (!o || typeof o !== "object" || Array.isArray(o))
215+
throw new Error(`${nodePath}.${k}: Expected array of objects. Is your schema valid?`);
214216
if (!("$ref" in o) || typeof o.$ref !== "string") return true;
215217
const ref = parseRef(o.$ref);
216218
return !ref.path.some((i) => i.startsWith("x-")); // ignore all custom "x-*" properties
217219
});
218220
}
219221
}
220-
222+
if (!rawNode || typeof rawNode !== "object" || Array.isArray(rawNode))
223+
throw new Error(
224+
`${nodePath}: Expected object, got ${Array.isArray(rawNode) ? "array" : typeof rawNode}. Is your schema valid?`
225+
);
221226
if (!("$ref" in rawNode) || typeof rawNode.$ref !== "string") return;
222227
const node = rawNode as unknown as ReferenceObject;
223228

0 commit comments

Comments
 (0)