json-schema
json-schema copied to clipboard
Validations always return true with ActionController::Parameters in rails 5
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