Paramsx

CI

Paramsx provides functionally to whitelist and validate parameters

Objective

We dont need wait for ecto raise a error in changeset to see a missing key in params

Installation

def deps do
  [
    {:paramsx, "~> 0.4.1"}
  ]
end

Handlers

We have a handler to return a json for your, in your module responsible for the action_fallback from phoenix you can do:

defmodule YourModuleOfFalback do
  use Paramsx.ErrorHandlerFallback
  .
  .
  .
end

Usage

Filter with required and optional params

Example:

iex> Paramsx.filter(%{"foo" => "bar", "other" => "value"}, [required: [:foo], optional: []])
{:ok, %{"foo" => "bar"}}

# You have to explicit say that is list when have it:
iex> Paramsx.filter(%{"foo" => [%{"bar" => "value_bar"}]}, required: [foo_list: [:bar]])
{:ok, %{foo: [%{bar: "value_bar"}]}}

# If some error appear was triggered the return will be:
iex> Paramsx.filter(%{"foo" => "bar", "foo2" => "bar2"}, required: [:foo3])
{:error, %{missing_keys: [:foo3]}} 

Incoming improvements:

License

Apache License, Version 2.0