Skip to content

Commit

Permalink
support cases where the request parameter is not a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu-sato committed Jul 24, 2022
1 parent 4dc74b1 commit 30ee28b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/committee/schema_validator/hyper_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def request_unpack(request)
coerce_form_params(request_param) if validator_option.coerce_form_params && is_form_params
request.env[validator_option.request_body_hash_key] = request_param

request.env[validator_option.params_key] = Committee::Utils.indifferent_hash
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param))
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request_param))
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash))
raise BadRequest, "Invalid JSON input. Require object with parameters as keys when path parameter exists." if !request_param.is_a?(Hash) && (query_param != {} || param_matches_hash != {})

request.env[validator_option.params_key] = Committee::Utils.deep_copy(request_param) || Committee::Utils.indifferent_hash
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param)) if query_param != {}
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash)) if param_matches_hash != {}
end

def coerce_form_params(parameter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(params, schema, options = {})
end

def call!
coerce_object!(@params, @schema)
coerce_value!(@params, @schema)
end

private
Expand Down

0 comments on commit 30ee28b

Please sign in to comment.