The Speck compiler can fail to compile a seemingly valid schema if a handful of conditions are met for an attribute:
- The attribute is a container:
attribute :foo do or attribute [:foo] do
- The attribute has opts:
optional: true, default: %{}, etc.
- The attribute only contains one attribute inside itself
Then Speck will fail to compile the schema with an error that looks like this:
Compiling protocol/foo/bar.ex
error: undefined function attribute/2 (there is no such import)
└─ nofile:10
Example schema:
struct Foo.Bar
name "foo_bar"
attribute :top_level do
attribute :unix_timestamp, :integer
attribute [:data_points], optional: true do
attribute :value, :integer
end
end
The problem occurs because attribute [:data_points], optional: true do only contains one attribute :value. If another element were added inside, Speck would compile it correctly.
While this schema should probably be altered to read attribute :data_points, [:integer], optional: true, there's no guarantee that some external, third-party API is as optimized as it could be.
The Speck compiler can fail to compile a seemingly valid schema if a handful of conditions are met for an attribute:
attribute :foo doorattribute [:foo] dooptional: true,default: %{}, etc.Then Speck will fail to compile the schema with an error that looks like this:
Example schema:
The problem occurs because
attribute [:data_points], optional: true doonly contains one attribute:value. If another element were added inside, Speck would compile it correctly.While this schema should probably be altered to read
attribute :data_points, [:integer], optional: true, there's no guarantee that some external, third-party API is as optimized as it could be.