Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/vocabularies/unevaluated/unevaluatedProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ const def: CodeKeywordDefinition = {
: gen.if(unevaluatedStatic(props, key), () => unevaluatedPropCode(key))
)

if (isForced && it.errorPath.emptyStr()) {
if (isForced && it.errorPath.emptyStr() && !it.compositeRule) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip forced static check under composite rules (anyOf/oneOf)

// $refs are compiled into functions
// We need to check in runtime if function was called from allOf.
// We need to check only on the top level of the function:
// it is ensured with `it.errorPath.emptyStr()` check
gen.if(_`${N.isAllOfVariant} === 0`, staticCheck)
} else {
staticCheck()
if (!it.compositeRule || cxt.schema !== undefined) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In composite rules run static check only when schema explicitly provides unevaluatedProperties

staticCheck()
}
}
}

Expand Down
69 changes: 69 additions & 0 deletions spec/default_unevaluated_properties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,75 @@ describe("defaultUnevaluatedProperties=false option", function () {
assertInvalid(schemas, {foo: {baz: 1}})
assertInvalid(schemas, {foo: {bar: "string", baz: 1}})
})

it("should work correctly with anyOf", () => {
const schema1 = {
type: "object",
properties: {
address: {type: "string"},
},
anyOf: [
{
type: "object",
required: ["firstName", "lastName"],
properties: {
firstName: {type: "string"},
lastName: {type: "string"},
},
},
{
type: "object",
required: ["name"],
properties: {
name: {type: "string"},
},
},
],
}

const schemas = [schema1]
assertInvalid(schemas, {})
assertValid(schemas, {address: "someWhere", firstName: "John", lastName: "Doe"})
assertValid(schemas, {address: "someWhere", name: "John Doe"})
assertInvalid(schemas, {address: "someWhere", firstName: "John"})
assertInvalid(schemas, {address: "someWhere", foo: 1})
assertValid(schemas, {firstName: "John", lastName: "Doe"})
})

it("should work correctly with oneOf", () => {
const schema1 = {
type: "object",
properties: {
address: {type: "string"},
},
oneOf: [
{
type: "object",
required: ["firstName", "lastName"],
properties: {
firstName: {type: "string"},
lastName: {type: "string"},
},
},
{
type: "object",
required: ["name"],
properties: {
name: {type: "string"},
},
},
],
}

const schemas = [schema1]

assertInvalid(schemas, {})
assertValid(schemas, {address: "someWhere", firstName: "John", lastName: "Doe"})
assertValid(schemas, {address: "someWhere", name: "John Doe"})
assertInvalid(schemas, {firstName: "John", lastName: "Doe", name: "JD"})
assertInvalid(schemas, {address: "someWhere", foo: 1})
assertValid(schemas, {firstName: "John", lastName: "Doe"})
})
})

describe("validation with $refs", () => {
Expand Down
Loading