Skip to content

Commit

Permalink
Adding spec to demonstrate issue ajv-validator#815: fields should set…
Browse files Browse the repository at this point in the history
… path base
  • Loading branch information
Kurt Preston committed Feb 26, 2019
1 parent 2aa49ae commit 488b9f3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/issues/815_id_updates_ref_base.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

var Ajv = require('../ajv');
require('../chai').should();

describe.only('issue #815, id and $id fields should reset base', function() {
var schema = {
"type": "object",
"properties": {
"newRoot": {
"$id": "http://example.com/newRoot",
"properties": {
"recurse": {
"$ref": "#"
},
"name": {
"type": "string"
}
},
"required": ["name"],
"additionalProperties": false
}
},
"required": ["newRoot"],
"additionalProperties": false
};

var ajv = new Ajv();
var validate = ajv.compile(schema);

it('should set # to reference the closest ancestor with $id', function() {
validate({newRoot: {
name: 'test'
}}) .should.equal(true);

validate({newRoot: {
name: 'test',
recurse: {
name: 'test2'
}
}}) .should.equal(true);
});

it('should NOT set # to reference the absolute document root', function() {
validate({newRoot: {
name: 'test',
recurse: {
newRoot: {
name: 'test2'
}
}
}}) .should.equal(false);
});
});

0 comments on commit 488b9f3

Please sign in to comment.