Skip to content

Proposal: Support string keys in path_params? #545

Description

@IgnacioGoldchluk

Hello

I have a use case where I have to construct requests based on user input (OpenAPI documents), these contain arbitrary path params like /users/{user_id} and arbitrary query parameters. The query :paramscan be kept as a list of [{"key", value}] because they are passed directly to URI.encode_query/1. For :path_params they must be first converted to atom because the code assumes params to be a keyword list. I can do String.to_atom on the :path_params but that is susceptible to atom exhaustion attack.

Would it be possible to support also string keys for :path_params, the same as in query :params? In the apply_path_params function, instead of assuming a keyword list

params[String.to_existing_atom(key)]

we could do something like this?

def path_param(params, key) do 
  case List.keyfind(params, key, 0) do
    {_key, value} -> value
    nil -> params[String.to_exsting_atom(key)]
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions