@@ -22,7 +22,10 @@ const Dereference = {
22
22
23
23
if ( Array . isArray ( value ) ) {
24
24
// Schema definition returns an array for this property, return the array with all refs resolved
25
- return value . map ( ( item , i ) => Schema . proxy ( this . join ( target . $id , `${ property } /${ i } ` ) , item ) )
25
+ return value . map ( ( item , i ) => {
26
+ const $ref = item . $ref || this . join ( target . $id , `${ property } /${ i } ` )
27
+ return Schema . resolve ( $ref , target . $id )
28
+ } )
26
29
} else if ( value !== null && typeof value === 'object' ) {
27
30
// Schema definition returns an object for this property, return the subschema and proxy it
28
31
return Schema . proxy ( this . join ( target . $id , property ) , value )
@@ -54,10 +57,15 @@ const DelegateToDefinition = {
54
57
}
55
58
56
59
// Class to browse schemas, resolve refs, and validate data
57
- class Schema {
58
- static resolve ( $ref , $id = undefined ) {
60
+ export class Schema {
61
+ static resolve ( $ref , $id = BaseURI ) {
59
62
const { href } = new URL ( $ref , $id )
60
- return this . proxy ( href , ajv . getSchema ( href ) . schema )
63
+ const validator = ajv . getSchema ( href )
64
+
65
+ if ( ! validator ) throw new TypeError ( 'Schema not found: ' + href )
66
+ if ( ! validator . proxy ) validator . proxy = Schema . proxy ( href , validator . schema )
67
+
68
+ return validator . proxy
61
69
}
62
70
63
71
static proxy ( $id , definition ) {
@@ -89,4 +97,4 @@ class Schema {
89
97
}
90
98
}
91
99
92
- export const schema = Schema . resolve ( BaseURI )
100
+ export const schema = Schema . resolve ( '#' )
0 commit comments