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

Add validation for header parameters #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pablobcb
Copy link

@pablobcb pablobcb commented Feb 7, 2018

PR for #155

Add validation for header parameters. The current implementation is full of duplicated code, but due the fact that the algorithm recursively consume the head of parameters until it produces an :ok, I wasnt able to figure out how to generalize and keep it current structure ...

If you want, I can try to wrap everything in Enum.all or whatever you suggest..

This is my first opensource contribution and my first month using elixir, so I'm sorry if I screwed anything up ..

Are the tests ok? Are they in the right place? Besides the changelog, should I add anything to this PR?

end

defp validate_header_params([{"string", _name, _val, _} | parameters]) do
validate_query_params(parameters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a copy & paste bug here :)

defp remove_base_path([_path | rest], [_base_path | base_path_rest]) do
remove_base_path(rest, base_path_rest)
end
end

defp validate_header_params([]), do: :ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_header_params/1 looks very similar to validate_query_params/1.
I think they can be combined into something like validate_parameter_list.

validate_header_params/2 is fine, since it needs to pull the params from a different key in the Conn anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to fix this as soon as I can

defp get_header_value(headers, header_name) do
header_name_down_case = String.downcase(header_name)

headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a handy function in the erlang std lib to search a list of tuples:

:lists.keyfind(header_name_down_case, 1, headers) || nil

Copy link
Contributor

@mbuhot mbuhot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my first opensource contribution and my first month using elixir

Congrats! 🎉 and thankyou ❤️ !

Are the tests ok?

👍 Tests look good to me

Besides the changelog, should I add anything to this PR?

I looks like your editor is auto-formatting the file in the Elixir 1.6 style?
Could you separate it into two commits? One to reformat the file, and another to add the header param validations.

@mbuhot
Copy link
Contributor

mbuhot commented Feb 17, 2018

@pablobcb most of the code from validate_plug has been moved into a separate module PhoenixSwagger.ConnValidator in #129.
You should be able to add the validate_header functions into that module.

@soundmonster
Copy link
Contributor

@pablobcb I'm happy to help rebasing your changes. Feel free to reach out any time.

@pablobcb
Copy link
Author

@soundmonster feel free to do it, Im currently moving to another city and dont know when I ll have the time to do it

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

Successfully merging this pull request may close these issues.

3 participants