Skip to content

Commit

Permalink
fix: correctly initialize evaluated properties with nested anyOf (etc…
Browse files Browse the repository at this point in the history
….), closes #1515
  • Loading branch information
epoberezkin committed Mar 26, 2021
1 parent 46d91d7 commit 6014412
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compile/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const mergeEvaluated: MergeEvaluated = {
gen.if(
_`${from} === true`,
() => gen.assign(to, true),
() => gen.code(_`Object.assign(${to}, ${from})`)
() => gen.assign(to, _`${to} || {}`).code(_`Object.assign(${to}, ${from})`)
)
}),
mergeToName: (gen, from, to) =>
Expand Down
28 changes: 28 additions & 0 deletions spec/issues/1515_evaluated_properties_nested_anyof.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import _Ajv from "../ajv2019"
import * as assert from "assert"

describe("tracking evaluated properties with nested anyOf", () => {
it("should initialize evaluated properties", () => {
const ajv = new _Ajv()

const schema = {
type: "object",
anyOf: [
{
required: ["foo"],
properties: {foo: {}},
},
{
anyOf: [
{
properties: {bar: {}},
},
],
},
],
}

const validate = ajv.compile(schema)
assert.strictEqual(validate({bar: 1}), true)
})
})

0 comments on commit 6014412

Please sign in to comment.