Skip to content

Commit bf43750

Browse files
fix: reset json pointer in merged allOf schema (#482)
1 parent e08e2e7 commit bf43750

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ function mergeAllOfSchema (location, schema, mergedSchema) {
493493
mergedSchema.$id = `merged_${randomUUID()}`
494494
ajvInstance.addSchema(mergedSchema)
495495
location.schemaId = mergedSchema.$id
496+
location.jsonPointer = '#'
496497
}
497498

498499
function buildInnerObject (location) {

test/ref.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,3 +1891,38 @@ test('input schema is not mutated', (t) => {
18911891
t.equal(output, '{"obj":"test"}')
18921892
t.same(schema, clonedSchema)
18931893
})
1894+
1895+
test('anyOf inside allOf', (t) => {
1896+
t.plan(1)
1897+
1898+
const schema = {
1899+
anyOf: [
1900+
{
1901+
type: 'object',
1902+
allOf: [
1903+
{
1904+
properties: {
1905+
a: {
1906+
anyOf: [
1907+
{ const: 'A1' },
1908+
{ const: 'A2' }
1909+
]
1910+
}
1911+
}
1912+
},
1913+
{
1914+
properties: {
1915+
b: { const: 'B' }
1916+
}
1917+
}
1918+
]
1919+
}
1920+
]
1921+
}
1922+
1923+
const object = { a: 'A1', b: 'B' }
1924+
const stringify = build(schema)
1925+
const output = stringify(object)
1926+
1927+
t.equal(output, JSON.stringify(object))
1928+
})

0 commit comments

Comments
 (0)