dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
425 stars 110 forks source link

Struct extension always produces failure #374

Closed Sorc96 closed 2 years ago

Sorc96 commented 3 years ago

Describe the bug

Providing valid input to a schema inferred from a Dry::Struct results in failure, presumably because the value is not a Hash anymore. Here I took the example that is used in the specs for this extension. Interestingly, there does not seem to be a spec for a success scenario.

To Reproduce

require "dry-struct"
require "dry-schema"

Dry::Schema.load_extensions :struct

struct = Dry.Struct(name: "string", email: "string")

schema = Dry::Schema.define do
  required(:foo).value(struct)
end

input = {foo: {name: "John", email: "legit@email"}}

schema.(input).errors.to_h # => {:foo=>["must be a hash"]}

Expected behavior

Schema result should have no errors.

My environment

flash-gordon commented 3 years ago

Lol it seems I was obsessed with errors, it should be (args[0].schema) here I'm pretty sure https://github.com/dry-rb/dry-schema/pull/253/files#diff-2b4a17c0dff23442d43af91a54e7c3118d909217a35a63fb6bcf5d2d13ed0181R21