Open Grasseh opened 4 years ago
Thanks for the report. With the maybe
method though, the expected type is ["nil", "integer"]
in this case, required
key in the meta data means the key is optional, it's not about the value under that key. This is a bit tricky because the AST as we have it now, doesn't clearly specify that we're dealing with "a maybe value". It's represented like this:
[:key, [:phone, [:implication, [[:not, [:predicate, [:nil?, [[:input, Undefined]]]]], [:predicate, [:str?, [[:input, Undefined]]]]]]]]
This translates to "if the value is not nil, then it must be a string". Which is great, but in case of the info
plugin I think it's ambiguous because you may have other negated predicates (represented as [:not, ...]
nodes) that are regular predicates without the special "maybe" meaning.
I think this should be properly addressed in 2.0.0 once we extend the AST with additional meta-data that could be used here, otherwise we could only fix it for the maybe case while breaking it for any negated predicate.
Thanks for the report. With the
maybe
method though, the expected type is["nil", "integer"]
in this case,required
key in the meta data means the key is optional, it's not about the value under that key. This is a bit tricky because the AST as we have it now, doesn't clearly specify that we're dealing with "a maybe value". It's represented like this:[:key, [:phone, [:implication, [[:not, [:predicate, [:nil?, [[:input, Undefined]]]]], [:predicate, [:str?, [[:input, Undefined]]]]]]]]
This translates to "if the value is not nil, then it must be a string". Which is great, but in case of the
info
plugin I think it's ambiguous because you may have other negated predicates (represented as[:not, ...]
nodes) that are regular predicates without the special "maybe" meaning.I think this should be properly addressed in 2.0.0 once we extend the AST with additional meta-data that could be used here, otherwise we could only fix it for the maybe case while breaking it for any negated predicate.
@solnic It seems this has been closed for a little bit, are we still planning on addressing this case for 2.0.0?
@carbroj yes this will be done eventually. Marking as "help wanted" for now.
Describe the bug
Using a
maybe
in a schema breaks the info option to generate an AST-parsed hash with the following stack-trace:To Reproduce
Open a terminal with irb or whatever environment you use. This uses the example code for
maybe
found here: https://dry-rb.org/gems/dry-schema/1.5/optional-keys-and-values/Expected behavior
I'd expect an hash to be produced without exception, just like the following does when the
maybe
is replaced by afilled
:{:keys=>{:email=>{:required=>true, :type=>"string"}, :age=>{:required=>false, :type=>"integer"}}}
Your environment