Closed
Description
I'd like to be able to do an action before and after each field validation, and then have the option to redo the validation after the action. This would help to accept a JSON document that has some invalid entries, but could still be accepted with some modification. Example use cases:
- Invalid Format: Fix date field formats prior to validating. For example, if format = date-time, then reformat the date, and then re-validate.
- Invalid Value: Remove invalid values after failing validation. For example, if a value fails a test, remove it from the input, and then re-validate.
This could be achieved by either of the following:
- Callback: Allow a callback function before each validation and a callback function after each validation. Both callbacks would need access to the relevant input data and corresponding piece of the JSON schema. The post validation callback would need access to the result of the validation, and be able to optionally call the validation again after possibly making changes to the input data.
- Iterator: Have an iterator (e.g. https://php.net/manual/en/class.iterator.php) where the validations could be applied one field at a time (and optionally be reapplied after possibly making changes to the input data). The user of the iterator would need access to the same information as the callback functions.