Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when calling end point with no parameters #26

Open
eflukx opened this issue Dec 21, 2019 · 1 comment
Open

Error when calling end point with no parameters #26

eflukx opened this issue Dec 21, 2019 · 1 comment

Comments

@eflukx
Copy link

eflukx commented Dec 21, 2019

Seems that PR #20 breaks calling end points that have no parameters.

When doing so I get a NoMethodError: undefined method 'reduce' for nil:NilClass originating from operation_builder.rb:61:in strip_headers!

It seems that in that case operation_parameters == nil is not handled. Made a quick fix for myself to get things working again, setting operation_parameters to [] when nil

Although this patch makes thins work for me now, probably not the best method? After having a quick look at the code, I presume that strip_headers! may just return nil when operation_parameters == nil.

@telekid As the author of the PR, maybe you can have a look at this? Very much appreciated!

def strip_headers!(operation_parameters:, request_parameters:)
  operation_parameters ||= [] # <--- 'hack' handling nil values
  header_names = operation_parameters.reduce([]) do |memo, param|
    memo.push(param["name"].downcase) if param["in"] == 'header'
    memo
  end

  headers = request_parameters.select { |key, val| header_names.include?(key)}
  request_parameters.reject! { |key, val| header_names.include?(key) }
  headers.empty? ? nil : headers
end
@slithernix
Copy link

Came here to post this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants