From 488b9f37d84439b8b8382321c145eef1cdbda392 Mon Sep 17 00:00:00 2001 From: Kurt Preston Date: Tue, 26 Feb 2019 14:39:44 -0600 Subject: [PATCH] Adding spec to demonstrate issue #815: fields should set path base --- spec/issues/815_id_updates_ref_base.spec.js | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 spec/issues/815_id_updates_ref_base.spec.js diff --git a/spec/issues/815_id_updates_ref_base.spec.js b/spec/issues/815_id_updates_ref_base.spec.js new file mode 100644 index 000000000..2d68b270b --- /dev/null +++ b/spec/issues/815_id_updates_ref_base.spec.js @@ -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); + }); +});