What I think is happening here is that the repetition of the reference to root.schema.json is being resolved down to $refs in later references. However because those sub schemas (sub1.schema.json) include as $id that changes the base uri for resolution. The result is #/oneOf/0/allOf/0 is being resolved from sub2.schema.json and not from root.schema.json.
When passed into AJV this then results in.
MissingRefError: can't resolve reference #/oneOf/0/allOf/0 from id sub2.schema.json
Removing the $id from sub*.schema.json which prevents the base uri from being changed corrects the issue.
Sample https://github.com/phawxby/json-ref-example/blob/main/src/example.ts
What I think is happening here is that the repetition of the reference to
root.schema.json
is being resolved down to$refs
in later references. However because those sub schemas (sub1.schema.json
) include as$id
that changes the base uri for resolution. The result is#/oneOf/0/allOf/0
is being resolved fromsub2.schema.json
and not fromroot.schema.json
.When passed into AJV this then results in.
Removing the
$id
fromsub*.schema.json
which prevents the base uri from being changed corrects the issue.Compiled output