trailblazer / reform

Form objects decoupled from models.
https://trailblazer.to/2.1/docs/reform.html
MIT License
2.49k stars 184 forks source link

Skipped property is still passed for validation #512

Open AndKiel opened 4 years ago

AndKiel commented 4 years ago

Complete Description of Issue

I want to have an optional validation. I'm using skip_if option when declaring property on a form. In the validation block I'm making it optional inside params so if the property is not passed to the validation, it would still validate successfully.

Steps to reproduce

Branch in my project: https://github.com/AndKiel/tournaments-api/tree/55eaf06f5e45e3969b0bc2720306d91e64aea6a3

Relevant files:

Test run focused on the form spec and contract spec (it still has focus on the form spec from the other issue): https://github.com/AndKiel/tournaments-api/pull/29/checks?check_run_id=735646841

Expected behavior

I'm expecting skipped property not to be passed to the validation at all. When using Dry::Validation::Contract and hash without a key is passed for the call it works as expected and validation passes. In Reform it's broken.

Actual behavior

Property key is still present and passed to validation with the value from validate() invocation despite the fact that property is declared with skip_if option.

System configuration

Reform version: v2.3.1 (latest) dry-validation version: v1.5 (latest)