( ref: string, pointer: string, ctx: ReadContext )
| 491 | } |
| 492 | |
| 493 | const resolveRef = ( |
| 494 | ref: string, |
| 495 | pointer: string, |
| 496 | ctx: ReadContext |
| 497 | ): RefTarget => { |
| 498 | const refPointer = `${pointer}/$ref` |
| 499 | if (ref === "#" || ref.startsWith("#/")) |
| 500 | return resolvePointer(ref, ref.slice(1), ctx.resource, refPointer, ctx) |
| 501 | ctx.resourcesByUri ??= indexResources(ctx) |
| 502 | let uri: URL |
| 503 | try { |
| 504 | uri = new URL(ref, ctx.resource.uri) |
| 505 | } catch { |
| 506 | return throwParseError(writeUnresolvableRefMessage(ref, refPointer)) |
| 507 | } |
| 508 | const fragment = uri.hash.slice(1) |
| 509 | uri.hash = "" |
| 510 | const resource = ctx.resourcesByUri[uri.href] |
| 511 | if (isPlainAnchor(fragment)) { |
| 512 | const anchored = ctx.resourcesByUri[`${uri.href}#${fragment}`] |
| 513 | if (anchored) { |
| 514 | return { |
| 515 | schema: anchored.schema, |
| 516 | resource: resource ?? anchored, |
| 517 | fragment |
| 518 | } |
| 519 | } |
| 520 | return throwParseError( |
| 521 | resource ? |
| 522 | writeUnresolvableRefMessage(ref, refPointer) |
| 523 | : writeUnsupportedRefMessage(ref, refPointer) |
| 524 | ) |
| 525 | } |
| 526 | if (!resource) |
| 527 | return throwParseError(writeUnsupportedRefMessage(ref, refPointer)) |
| 528 | return resolvePointer(ref, fragment, resource, refPointer, ctx) |
| 529 | } |
| 530 | |
| 531 | // segments are percent-decoded, then unescaped (RFC 6901) |
| 532 | const resolvePointer = ( |
no test coverage detected