-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
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 doorattribute [: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
endThe 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.
Metadata
Metadata
Assignees
Labels
No labels