-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
If a map attribute is marked as optional, and the incoming params do not have that data, then the struct that Speck outputs will have an empty(-ish) map for that attribute. Here's a barebones example:
struct MyNamespace.FooData
name "foo_data"
attribute :name, :string
attribute :status, :atom, values: [:ok, :not_okay]
attribute :data, optional: true do
attribute :timestamp, :datetime
attribute [:values] do
attribute :value_1, :integer
attribute :value_2, :string
end
endThen, in iex:
json = """
{
"name": "foo",
"status": "ok"
}
"""
message = Jason.decode!(json)
Speck.validate(MyNamespace.FooData, message)If you run this, you'll get this returned:
{
:ok,
%MyNamespace.FooData{
name: "foo",
status: :ok,
data: %{
values: []
}
}
}There are two interesting things I'm seeing here:
:dataexists at all in the returned struct.:valuesis included in the map, but:timestampisn't.