These are chat archives for dry-rb/chat

22nd
Feb 2017
Don Morrison
@elskwid
Feb 22 2017 00:44
Agreed. I like the divide.
Piotr Solnica
@solnic
Feb 22 2017 07:00
I should mention that “schema” will be an abstract concept in dry-validation
so any object implementing required interface will work
Tim Riley
@timriley
Feb 22 2017 09:31
Oh good, I was going to ask about whether a validation class would require a local schema definition, or whether you could pass one in.
In fact, in a system where your schemas are on the edge, would you need to pass it to the validation object at all, given you know you've already passed your data through it?
Piotr Solnica
@solnic
Feb 22 2017 09:32
@timriley yes because a schema defines the input structure so we can easily extract specific values for other rules
a validator needs to know what it’s dealing with
so ie you’d be able to define an HTTP schema at the boundary, and use it in a validator by connecting the two
but you won’t have to define it in the validator itself
I would like to have a way of defining schemas for every http endpoint somehow
we can also do this the other way around, define plain schemas in validators, and infer http schemas from them for http end-points
Tim Riley
@timriley
Feb 22 2017 09:40
Right
I like the of comprehensive endpoint scheme definition
The idea of*
Piotr Solnica
@solnic
Feb 22 2017 09:43
r.get(“search”) do |r|
  r.schema do
    optional(:q).filled(:str?)
  end

  r.view(‘users.index’, params: { q: s[:q] })
end
maybe this is doable for roda ^
this can define schemas on the fly (and cache them) and then expose s (or something) to access processed params
it can register these schemas in the container and then you could just do:
class UserSearchValidator < Dry::Validation::Validator
  include Import(schema: “schemas.users.search”)

  rule(:q) { |q| … }
end
not the best example but you should see the idea regardless
the beauty of this approach is that http stuff doesn’t leak into domain land
@timriley ^^
we can easily add a shortcut in dry-web ie class UserSearchValidator < Dry::Validation[“schemas.users.search”]
Piotr Solnica
@solnic
Feb 22 2017 09:50
I’m hoping that if we make this really easy, folks will start validating http params for all end-points, this should make apps more secure and crash less
I also love the fact it can self-document end-points
we can easily add additional APIs for annotating schemas with docs, and generate API docs from that, all kinds of nice things are possible
Tim Riley
@timriley
Feb 22 2017 09:53
Yeah, this looks promising!
Piotr Solnica
@solnic
Feb 22 2017 09:55
yeah :) I think this will be it :)
I honestly can’t wait to start working on this, dry-v has been in the backround of my brain for many months, but I didn’t have time to work on it because of rom 3.0
Tim Riley
@timriley
Feb 22 2017 10:01
Yay :)
Not sure how r.schema could register items in the container though, since the container gets frozen and the routing block isn’t evaluated until each request comes in.
that’s one problem with dynamic routes like roda's
Piotr Solnica
@solnic
Feb 22 2017 10:02
you mean, another problem? O_o
Tim Riley
@timriley
Feb 22 2017 10:02
HEH.
Piotr Solnica
@solnic
Feb 22 2017 10:02
well, we may need a special schema registry that we can import into app’s container
and that one won’t be frozen
I don’t think roda apps are deeply frozen
so it should work
Tim Riley
@timriley
Feb 22 2017 10:07
yeah...
and eventually we design dry-router and dry-controller, right?
Piotr Solnica
@solnic
Feb 22 2017 10:08
haha…NOPE although @AMHOL have experimented with this already…:D
personally I’m more interested in plugging hanami stuff into dry-web
I don’t feel like working on http routers and related things tbf, but I wouldn’t be against it if somebody really wants to do it and be serious about it
Tim Riley
@timriley
Feb 22 2017 10:10
yeah
Hanami’s stuff could fit pretty nicely.
Piotr Solnica
@solnic
Feb 22 2017 10:10
well it does fit, I built rodakase-lotus last year (as a PoC)
Tim Riley
@timriley
Feb 22 2017 10:10
yeah, I remember… lotuskase :)
Piotr Solnica
@solnic
Feb 22 2017 10:10
right, this :)
timriley @timriley adds to TODO list
Andy Holland
@AMHOL
Feb 22 2017 15:06
@solnic @timriley yeah I did experiment with a stateless routing tree router, it was a failed experiment
Pablo Herrero
@pabloh
Feb 22 2017 22:31
Hey guys, how can you do introspection on a dry-validation schema?
Piotr Solnica
@solnic
Feb 22 2017 22:35
[11] pry(main)> Dry::Validation.Schema { required(:name).filled }.class.rule_ast
=> [[:rule, [:name, [:and, [[:rule, [:name, [:predicate, [:key?, [[:name, :name], [:input, Undefined]]]]]], [:rule, [:name, [:key, [:name, [:predicate, [:filled?, [[:input, Undefined]]]]]]]]]]]]]
@pabloh ie like this ^
depends what you need
the ast is the most detailed one
Pablo Herrero
@pabloh
Feb 22 2017 22:43
@solnic , just the required/optional fields
the names only
Russell Edens
@rx
Feb 22 2017 23:03
@paploh I created this and have started using it: https://github.com/dry-rb/dry-validation/issues/67#issuecomment-246497364
Russell Edens
@rx
Feb 22 2017 23:15
@pabloh I'm currently using gem 'dry-metadata', :github=>'voomify/dry-metadata', :branch => 'develop' with dry-validation 0.10.5