Commit 6506ecf
authored
👌 Include JSON location in $ref resolution errors (#1736)
## Summary
`resolve_refs` errors (circular / invalid / missing `$ref`,
`$ref`-with-siblings) gave **no** indication of *where* the faulty
reference lived, so on a non-trivial `needs_schema_definitions` users
had to hunt through the whole config to find it. Other config errors
already carry a schema name via `get_schema_name` (`id[idx]`); the
global `$ref`-resolution pass was the gap.
This threads the JSON path of the current item through the recursive
`resolve_refs` walk and appends it to each error message.
## Before → after
```text
Circular reference detected for 'type-impl'.
→ Circular reference detected for 'type-impl' (at $defs.type-impl.allOf[0]).
Reference 'not-exist' not found in definitions.
→ Reference 'not-exist' not found in definitions (at schemas[0].validate.local).
Invalid $ref value: 123, expected a string.
→ Invalid $ref value: 123, expected a string (at schemas[0].validate.local).
Invalid $ref value: type-impl, expected to start with '#/$defs/'.
→ Invalid $ref value: type-impl, expected to start with '#/$defs/' (at schemas[0].validate.local).
```
The path is the JSON location from the root of
`needs_schema_definitions` (`schemas[i]...` or `$defs.<name>...`),
inherently encoding which schema (by index) the `$ref` sits in. When
there is no path (root), the suffix is omitted, so behaviour is
unchanged for that degenerate case.
## Notes
- Snapshot-only test impact: the five `ref_*` config fixtures in
`tests/schema/__snapshots__/test_schema.ambr` now include the location.1 parent 59b8b4e commit 6506ecf
2 files changed
Lines changed: 34 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
246 | 254 | | |
247 | 255 | | |
248 | 256 | | |
249 | 257 | | |
250 | 258 | | |
251 | 259 | | |
252 | | - | |
| 260 | + | |
253 | 261 | | |
254 | 262 | | |
255 | 263 | | |
256 | | - | |
| 264 | + | |
257 | 265 | | |
258 | 266 | | |
259 | 267 | | |
260 | 268 | | |
261 | | - | |
| 269 | + | |
262 | 270 | | |
263 | 271 | | |
264 | 272 | | |
265 | | - | |
| 273 | + | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
269 | 277 | | |
270 | | - | |
| 278 | + | |
271 | 279 | | |
272 | 280 | | |
273 | 281 | | |
274 | | - | |
| 282 | + | |
275 | 283 | | |
276 | 284 | | |
| 285 | + | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
280 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
281 | 296 | | |
282 | 297 | | |
283 | 298 | | |
284 | | - | |
285 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
286 | 303 | | |
287 | | - | |
288 | | - | |
| 304 | + | |
| 305 | + | |
289 | 306 | | |
290 | 307 | | |
291 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
582 | | - | |
| 582 | + | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
| 585 | + | |
586 | 586 | | |
587 | 587 | | |
588 | | - | |
| 588 | + | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
| 591 | + | |
592 | 592 | | |
593 | 593 | | |
594 | | - | |
| 594 | + | |
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| |||
0 commit comments