From bf43750b179d9aee77384ab0f5ecb7aa0da6bdab Mon Sep 17 00:00:00 2001 From: Ivan Tymoshenko Date: Wed, 29 Jun 2022 17:58:39 +0300 Subject: [PATCH] fix: reset json pointer in merged allOf schema (#482) --- index.js | 1 + test/ref.test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/index.js b/index.js index 11a67a11..083f0fc2 100644 --- a/index.js +++ b/index.js @@ -493,6 +493,7 @@ function mergeAllOfSchema (location, schema, mergedSchema) { mergedSchema.$id = `merged_${randomUUID()}` ajvInstance.addSchema(mergedSchema) location.schemaId = mergedSchema.$id + location.jsonPointer = '#' } function buildInnerObject (location) { diff --git a/test/ref.test.js b/test/ref.test.js index f9502c47..fce9d20e 100644 --- a/test/ref.test.js +++ b/test/ref.test.js @@ -1891,3 +1891,38 @@ test('input schema is not mutated', (t) => { t.equal(output, '{"obj":"test"}') t.same(schema, clonedSchema) }) + +test('anyOf inside allOf', (t) => { + t.plan(1) + + const schema = { + anyOf: [ + { + type: 'object', + allOf: [ + { + properties: { + a: { + anyOf: [ + { const: 'A1' }, + { const: 'A2' } + ] + } + } + }, + { + properties: { + b: { const: 'B' } + } + } + ] + } + ] + } + + const object = { a: 'A1', b: 'B' } + const stringify = build(schema) + const output = stringify(object) + + t.equal(output, JSON.stringify(object)) +})