ajv-validator/ajv

Referencing errors in complex schemas

codan84 opened this issue · 0 comments

What version of Ajv are you using? Does the issue happen if you use the latest version?

8.12, haven't tested with older versions

Ajv options object

{}

JSON Schema

const roomSchema = {
  $id: 'room.json',
  type: 'object',
  properties: {
    name: {
      type: 'string'
    }
  }
};

const houseSchema = {
  $id: 'base/house.json',
  type: 'object',
  properties: {
    rooms: {
      type: 'array',
      items: {
        $ref: 'room.json'
      }
    }
  }
}

Sample data

{}

Your code

https://runkit.com/codan84/ajv-refs/1.0.0
https://runkit.com/codan84/ajv-refs/1.1.0

var validate = ajv
  .addSchema(roomSchema, 'room.json')
  .compile(houseSchema)

console.log(validate(data));

Validation result, data AFTER validation, error messages

MissingRefError: can't resolve reference room.json from id base/house.json

What results did you expect?

I didn't expect reference error. I provided IDs that I believe to be fine. Neither full URIs (v1.1.0) nor paths (v1.0.0) seem to work.

Are you going to resolve the issue?

No? Asking for advise as to how to get these refs to work.