drops
drops copied to clipboard
Support for aliases / mapping between input keys and output fields
It would be nice to be able to map input keys to different output keys, similar to the key:
option of Parameter.
This would allow to easily convert between different field names across boundaries at data ingestion point.
For example, something like this (I'm using two different imaginary options in the example)
defmodule UserPayload do
use Drops.Contract
schema do
%{
required(:user_id, source_key: "userId") => string(),
required(:surname, aliases: ["lastName", "familyName"]) => string()
}
end
end
Which would allow me to conform the input map (e.g. from Jason.decode
)
{
"userId": "user-123",
"lastName": "Doe"
}
Into the output map:
%{
user_id: "user-123",
surname: "Doe"
}