Skip to content

Commit 670ea06

Browse files
committed
Support formats other than BASIC
1 parent 237ff45 commit 670ea06

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/basic-to-detailed.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { registerSchema, validate } from "@hyperjump/json-schema/draft-2020-12";
2-
import { BASIC, compile, getSchema } from "@hyperjump/json-schema/experimental";
2+
import { compile, DETAILED, getSchema } from "@hyperjump/json-schema/experimental";
33
import * as Instance from "@hyperjump/json-schema/instance/experimental";
44

55
/**
@@ -166,18 +166,16 @@ keywordHandlers["https://json-schema.org/keyword/minimum"] = {
166166

167167
/** @typedef {Record<string, Record<string, true>>} ErrorIndex */
168168

169-
/** @type (basicOutput: OutputUnit) => ErrorIndex */
170-
const constructErrorIndex = (basicOutput) => {
171-
/** @type ErrorIndex */
172-
const errorIndex = {};
173-
174-
if (basicOutput.valid) {
169+
/** @type (outputUnit: OutputUnit, errorIndex?: ErrorIndex) => ErrorIndex */
170+
const constructErrorIndex = (outputUnit, errorIndex = {}) => {
171+
if (outputUnit.valid) {
175172
return errorIndex;
176173
}
177174

178-
for (const error of /** @type OutputUnit[] */ (basicOutput.errors)) {
179-
errorIndex[error.absoluteKeywordLocation] ??= {};
180-
errorIndex[error.absoluteKeywordLocation][error.instanceLocation] = true;
175+
for (const errorOutputUnit of outputUnit.errors ?? []) {
176+
errorIndex[errorOutputUnit.absoluteKeywordLocation] ??= {};
177+
errorIndex[errorOutputUnit.absoluteKeywordLocation][errorOutputUnit.instanceLocation] = true;
178+
constructErrorIndex(errorOutputUnit, errorIndex);
181179
}
182180

183181
return errorIndex;
@@ -232,8 +230,8 @@ registerSchema({
232230

233231
const instance = { foo: 2 };
234232

235-
const basicOutput = await validate(subjectUri, instance, BASIC);
236-
const errorIndex = constructErrorIndex(basicOutput);
233+
const output = await validate(subjectUri, instance, DETAILED);
234+
const errorIndex = constructErrorIndex(output);
237235

238236
const schema = await getSchema(subjectUri);
239237
const { schemaUri, ast } = await compile(schema);

0 commit comments

Comments
 (0)