|
1 | 1 | 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"; |
3 | 3 | import * as Instance from "@hyperjump/json-schema/instance/experimental"; |
4 | 4 |
|
5 | 5 | /** |
@@ -166,18 +166,16 @@ keywordHandlers["https://json-schema.org/keyword/minimum"] = { |
166 | 166 |
|
167 | 167 | /** @typedef {Record<string, Record<string, true>>} ErrorIndex */ |
168 | 168 |
|
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) { |
175 | 172 | return errorIndex; |
176 | 173 | } |
177 | 174 |
|
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); |
181 | 179 | } |
182 | 180 |
|
183 | 181 | return errorIndex; |
@@ -232,8 +230,8 @@ registerSchema({ |
232 | 230 |
|
233 | 231 | const instance = { foo: 2 }; |
234 | 232 |
|
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); |
237 | 235 |
|
238 | 236 | const schema = await getSchema(subjectUri); |
239 | 237 | const { schemaUri, ast } = await compile(schema); |
|
0 commit comments