-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
Description
Hi, I possibly discovered a bug (or I am missing something). Here the scenario:
Basically there is this message I want to validate using Speck:
{
"type": "type",
"data": {
"devices": [
{
"name": "a name"
}
]
}
}
Then I define the spec according to the docs like this:
struct App.TheSpec
name "the_spec"
attribute :type, :string, values: ["type"]
attribute :data do
attribute [:devices] do
attribute :name, :string
end
end
Running my tests results in this error message:
** (ArgumentError) cannot convert the given list to a string.
To be converted to a string, a list must either be empty or only
contain the following elements:
* strings
* integers representing Unicode code points
* a list containing one of these three elements
Please check the given list or call inspect/1 to get the list representation, got:
[:devices]
Oddly I found out (a workaround) which made it work, by just adding a dummy attribute to the devices array, like this:
struct App.TheSpec
name "the_spec"
attribute :type, :string, values: ["type"]
attribute :data do
attribute [:devices] do
attribute :dummy, :string, optional: true
attribute :name, :string
end
end
So it seems like that Speck has an issue with validating the payload if there are arrays of maps, which only have one key: value pair. As soon as it are at least 2+ key: value pairs, it works.
Is this a legit bug, or am I using it wrong? Thanks for the help.