ruby-grape / ruby-grape/grape-swagger
parse_request_params error
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.1k
- Forks
- 479
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
In order to use swagger more convenient, I rewrite some attrs in Grape::Router::Route. And there is a problem when parsing the request params in the following code, for I add a Symbol type param behind an Array type param.
# lib/grape-swagger/endpoint.rb
def parse_request_params(params)
array_key = nil
params.select { |param| public_parameter?(param) }.each_with_object({}) do |param, memo|
name, options = *param
param_type = options[:type]
param_type = param_type.to_s unless param_type.nil?
array_key = name.to_s if param_type_is_array?(param_type)
options[:is_array] = true if array_key && name.start_with?(array_key)
memo[name] = options unless %w[Hash Array].include?(param_type) && !options.key?(:documentation)
end
end
So is it better to to delete array_key = nil to set array_key a local variable in the block.
And there is another doubt for me. Why do you set array_key = name.to_s and then judge whether name.start_with?(array_key)? Why not directly use options[:is_array] = true if param_type_is_array?(param_type)?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/grape-swagger/endpoint.rb at parse_request_params and reproduce the reported case with a Symbol parameter after an Array parameter. Trace array_key, param_type_is_array?, and public_parameter? to establish the intended array marking; done when the parsing error is resolved and the resulting parameter metadata matches the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100