Shaping flat maps into nested maps with changing data inputs

Nothing stops you from writing one generic module and each module for every of your APIs.

Also you can use metaprogramming like:

defmodule Example do
  use MyLib, flat_keys: @flat_keys ~w[occupation username]

  def parse("birthday", birthday) when is_integer(birthday) do
    naive = birthday |> DateTime.from_unix!() |> DateTime.to_naive()
    {~w[public_profile birthday], naive}
  end
end

Another way is to use an existing library like cozy_params:

In above topic I have suggested an interesting ideas for source and sources options. Those are already approved and once implemented it would suit your case perfectly.

See also related GitHub issue:

1 Like