Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where matching anyOf branch is not selected correctly (#1129)
This change improves the logic that selects a matching anyOf branch based on form data. Previously the behaviour was to just check if the form data was valid against an anyOf branch, however due to the permissive nature of JSON schema this has unexpected behaviour. For example, given the following schema: ```json { "type": "object", "anyOf": [ { "properties": { "foo": { "type": "string" } } }, { "properties": { "bar": { "type": "string" } } } ] } ``` The form data `{ bar: 'baz' }` will actually match the first branch. To mitigate this, when doing the matching, the branch schema is augmented to require at least one of the keys in the branch. For example the schema above would become: ```json { "type": "object", "anyOf": [ { "properties": { "foo": { "type": "string" } }, "anyOf": [ { "required": [ "foo" ] } ] }, { "properties": { "bar": { "type": "string" } }, "anyOf": [ { "required": [ "bar" ] } ] } ] } ``` Signed-off-by: Lucian <lucian.buzzo@gmail.com>
- Loading branch information