Skip to content

Commit 0277f4c

Browse files
committed
update: getDraft to throw if missing and return directly for single draft
1 parent 983852e commit 0277f4c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/SchemaNode.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import copy from "fast-copy";
22
import sanitizeErrors from "./utils/sanitizeErrors";
33
import settings from "./settings";
4-
import type {
5-
JsonSchemaReducer,
6-
JsonSchemaResolver,
7-
JsonSchemaValidator,
8-
Keyword,
9-
ValidationPath,
10-
ValidationResult
11-
} from "./Keyword";
4+
import type { JsonSchemaReducer, JsonSchemaResolver, JsonSchemaValidator, Keyword, ValidationPath } from "./Keyword";
125
import { createSchema } from "./methods/createSchema";
136
import { Draft } from "./Draft";
147
import { toSchemaNodes } from "./methods/toSchemaNodes";
@@ -43,6 +36,12 @@ export function isReduceable(node: SchemaNode) {
4336
}
4437

4538
function getDraft(drafts: Draft[], $schema: string) {
39+
if (!Array.isArray(drafts) || drafts.length === 0) {
40+
throw new Error(`Missing drafts in 'compileSchema({ $schema: "${$schema}" })'`);
41+
}
42+
if (drafts.length === 1) {
43+
return drafts[0];
44+
}
4645
return drafts.find((d) => new RegExp(d.$schemaRegEx).test($schema)) ?? drafts[drafts.length - 1];
4746
}
4847

0 commit comments

Comments
 (0)