Skip to content

Commit

Permalink
fix: reference after merge allOf (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm authored Jun 29, 2022
1 parent 6bcef0e commit edf1a87
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ function mergeAllOfSchema (location, schema, mergedSchema) {
}
}
delete mergedSchema.allOf

mergedSchema.$id = `merged_${randomUUID()}`
ajvInstance.addSchema(mergedSchema)
location.schemaId = mergedSchema.$id
}

function buildInnerObject (location) {
Expand Down
57 changes: 57 additions & 0 deletions test/issue-479.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'

const { test } = require('tap')
const build = require('..')

test('should validate anyOf after allOf merge', (t) => {
t.plan(1)

const schema = {
$id: 'schema',
type: 'object',
allOf: [
{
$id: 'base',
type: 'object',
properties: {
name: {
type: 'string'
}
},
required: [
'name'
]
},
{
$id: 'inner_schema',
type: 'object',
properties: {
union: {
$id: '#id',
anyOf: [
{

$id: 'guid',
type: 'string'
},
{

$id: 'email',
type: 'string'
}
]
}
},
required: [
'union'
]
}
]
}

const stringify = build(schema)

t.equal(
stringify({ name: 'foo', union: 'a8f1cc50-5530-5c62-9109-5ba9589a6ae1' }),
'{"name":"foo","union":"a8f1cc50-5530-5c62-9109-5ba9589a6ae1"}')
})

0 comments on commit edf1a87

Please sign in to comment.