json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

Validations always return true with ActionController::Parameters in rails 5

Open alisaifee opened this issue 7 years ago • 7 comments

With Rails 5 ActionController::Parameters no longer inherits from Hash. Using the controller params with json-schema therefore results in the validations always returning true

Example:

Test [11] > schema = {properties: {a: {type: "integer"}}}
{
    :properties => {
        :a => {
            :type => "integer"
        }
    }
}
Test [12] > props = ActionController::Parameters.new a: 'not-int'
<ActionController::Parameters {"a"=>"not-int"} permitted: false>
Test [13] > JSON::Validator.validate! schema, props
true
Test [14] > JSON::Validator.validate! schema, props.to_unsafe_h
JSON::Schema::ValidationError: The property '#/a' of type String did not match the following type: integer

alisaifee avatar Jan 29 '17 10:01 alisaifee