zfcampus / zf-content-validation

ZF2 module for automated input validation
BSD 3-Clause "New" or "Revised" License
20 stars 25 forks source link

Unexpected behavior with "use_raw_data" #59

Open dstockto opened 9 years ago

dstockto commented 9 years ago

If I set my controller's option for use_raw_data to false, I'd expect that instead of getting everything that's passed in (unfiltered expected fields as well as all the other stuff someone may be passing in) I would only get the filtered, expected fields. Previously it was common to grab just the filtered and expected values in the resource with something like

$data = $this->getInputFilter()->getValues()

However, it appears that if use_raw_data is false, you'll get the filtered expected values plus any other unfiltered, unexpected values as well which seems to be less than ideal.

Previously it was possible to ignore any incoming parameters that you didn't care about and the API would work. There is another new setting "allows_only_fields_in_filter" which if set to true means that it will actually send back a 422 validation error response for the fields that are not defined in your input filter.

It seems it would make sense to allow the resource method to receive only the valid, filtered values that were expected and throw away the rest. Right now the only way to do that is to grab the input filter from within the method and call getInputFilter()->getValues() or something similar.

I'd appreciate any thoughts or comments on it. Perhaps I'm just doing it wrong. It does seem that it'd be simpler to test if I knew I could just pass in and test with validated and filtered values and not need to worry about the input filter dependency within the method.

Thank you.

weierophinney commented 4 years ago

This repository has been closed and moved to laminas-api-tools/api-tools-content-validation; a new issue has been opened at https://github.com/laminas-api-tools/api-tools-content-validation/issues/6.