Skip to content

Commit

Permalink
fix: reset json pointer in merged allOf schema (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed Jun 29, 2022
1 parent e08e2e7 commit bf43750
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 35 additions & 0 deletions test/ref.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit bf43750

Please sign in to comment.