redwirelabs / speck

Input validation & protocol documentation
MIT License
9 stars 2 forks source link

invalid validation for spec with an array of strings #7

Open robdembitel opened 1 week ago

robdembitel commented 1 week ago

Hi,

I found a bug while validating this spec:

struct App.Specs.Location

name "app_specs_location"

attribute :type,          :string,    values: ["location"]
attribute :data do
  attribute :path,        [:string]
end

As defined in the spec above path must be an array containing values of type string.

Validating this invalid payload (it contains an integer instead of a string) with Spec should return an error, but it does not.

%{"type" => "location", "data" => %{"path" => ["valid string", 3]}}

In this case Speck.validate returns {:ok, ...}

amclain commented 1 week ago

Thanks! We're triaging this issue and aim to have a fix next week.

amclain commented 6 days ago

Hi @robdembitel,

We have identified this as a feature request and have opened ticket #8 and assigned @abelino to implement it. Speck is intended to work with third-party APIs that may not be the best behaved, and that a user of Speck may not have the ability to change. Due to this, Speck first makes a best-effort to coerce, and then validates. In other words, the attribute type is the output type rather than the input type. However, there are cases where strict validation (validation before coercion) would be helpful, so we're happy to add this feature.

Are you blocked without this?

robdembitel commented 6 days ago

Hi @amclain - all good. I am not blocked by this, yet it would be good to get the strict validation as you described.

Just let me know as soon as you have it - Thanks for adding the feature.