dry-rb / dry-schema

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

Fix info extension for maybe macro #471

Open santiagodoldan opened 10 months ago

santiagodoldan commented 10 months ago

Fixes info extension for maybe macro, it introduces nullable flag to represent whether a key is nullable or not.

    schema = Dry::Schema.JSON do
      required(:email).filled(:string)
      optional(:age).maybe(:integer)
    end

BEFORE

irb(main):030> schema.info
/usr/local/bundle/ruby/3.2.0/gems/dry-schema-1.13.3/lib/dry/schema/extensions/info/schema_compiler.rb:46:in `public_send': undefined method `visit_not' for #<Dry::Schema::Info::SchemaCompiler:0x00007fc01e0ce780 @keys={:email=>{:required=>true, :type=>"string"}, :age=>{:required=>false}}> (NoMethodError)

          public_send(:"visit_#{meth}", rest, opts)
          ^^^^^^^^^^^
Did you mean?  visit_and
               visit_set
               visit_key

AFTER

irb(main):156> schema.info
=> {:keys=>{:email=>{:required=>true, :nullable=>false, :type=>"string"}, :age=>{:required=>false, :nullable=>true, :type=>"integer"}}}
santiagodoldan commented 9 months ago

@solnic could you let me know if my changes make sense? it seems you implemented this class and it would be nice to understand if my changes are aligned with your initial idea, thanks 💯

santiagodoldan commented 9 months ago

@solnic Let me know if I need to apply any changes here, I'm not sure if what I did is aligned with your initial approach.