Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluggable validation? #13

Open
eoliphan opened this issue Sep 1, 2021 · 5 comments
Open

Pluggable validation? #13

eoliphan opened this issue Sep 1, 2021 · 5 comments

Comments

@eoliphan
Copy link

eoliphan commented Sep 1, 2021

Would be nice to be able to use say malli instead of spec

@oakes
Copy link
Owner

oakes commented Sep 3, 2021

The thing that makes spec integrate so well is the fact that specs and o'doyle attributes are both qualified keywords, so i can associate them together without any extra code. Not sure how to do this using libraries like malli since it doesn't use qualified keywords in this way.

You could define spec functions that use malli inside them though. For example...

;; normal spec
(s/def ::x number?)
(s/def ::y number?)
(s/def ::position (s/keys :req-un [::x ::y]))

;; spec using malli to validate
(def Position [:map [:x number?] [:y number?]])
(s/def ::position #(m/validate Position %))

But in this case the spec error would just say that the ::position spec failed but wouldn't give details about why it failed, so maybe not that useful.

@eoliphan
Copy link
Author

eoliphan commented Sep 3, 2021

So, one thing about Malli (despite the fact that most of the examples are more like Schema) is that the registry approach is well, pluggable lol. We actually chose to use it in a more, spec'ish fashion, since we liked spec's registry approach but wanted something a bit more programmable (come on Spec2!). We've a facade namespace coupled with a mutable registry. So we already do stuff like (ourspec/register! ::x number?) and so on. You can also basically bundle up a bunch of schemas (Position, RayGun, etc) and pass those around as well. But to your point, generalized support (w/o shimming through spec) would be more complex. You'd need to be able to pass in a registry, etc. Will do some poking around in the code.

SN. This is great stuff. After using Drools and Jess (so having to LISP anyway) in the Java world, then Clara which is awesome, but feels 'objecty' at times, O'Doyle really hits the spot. We're full-stack clojure, Fulcro, Pathom, Datomic, etc so this just slots right in.

@oakes
Copy link
Owner

oakes commented Sep 3, 2021

That is great to hear :D As for your custom registry, in that case you should be able to hook it in by overwriting the spec for odoyle.rules/insert. Right now it's using a custom conformer which gets the spec for the given attribute and tries to validate it. I think you could write your own conformer that pretty much does the same thing, except reads from your own registry and validates / throws errors via malli.

@eoliphan
Copy link
Author

eoliphan commented Sep 3, 2021

Ok cool. I'll check that out

@jtrunick
Copy link

I also want to use mall, I was planning on using their custom :properties to add a fully qualified keyword and pull those out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants