This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-27
Channels
- # admin-announcements (1)
- # aws-lambda (2)
- # beginners (48)
- # boot (231)
- # capetown (1)
- # cider (35)
- # cljs-dev (25)
- # cljsrn (74)
- # clojure (273)
- # clojure-austin (2)
- # clojure-berlin (5)
- # clojure-hk (1)
- # clojure-poland (1)
- # clojure-russia (50)
- # clojure-spec (63)
- # clojure-uk (58)
- # clojurescript (51)
- # cursive (5)
- # datomic (39)
- # defnpodcast (3)
- # dirac (13)
- # editors (6)
- # emacs (3)
- # hoplon (86)
- # jobs (2)
- # lein-figwheel (1)
- # liberator (3)
- # off-topic (10)
- # om (113)
- # onyx (34)
- # protorepl (29)
- # re-frame (2)
- # reagent (8)
- # remote-jobs (1)
- # ring (4)
- # test-check (42)
- # untangled (31)
- # yada (2)
I mean, I can use it with a keyword, but now I have something a bit more complex: a schema is either a reference (`{:$ref “some-string"}`) or a schema with a type
(when I s/or, it complains that it can’t find an appropriate method, which is true I guess; I wasn’t expecting it to even try that branch)
I tried doing with with s/or
this way:
(s/def ::schema
(s/or ::reference
(fn [m] (contains? m :$ref))
::direct-schema
(fn [m] (contains? m :type))))
I guess I can just use map? and it can later specify with keys — that appears to sorta work 🙂
(s/def ::$ref uuid?)
(s/def ::type keyword?)
(s/def ::schema (s/or ::reference (s/keys :req-un [::$ref]) ::direct-schema (s/keys :req-un [::type])))
Hello. Is it possible to assert properties about keys and values in a map using s/keys
without using the registry?
@michaeldrogalis: You can put keys into s/keys
that aren't in the registry, and the spec will just check for their existence. It is not possible to provide inline specs to validate map values.
@codonnell: Thanks for the confirmation.
no problem
http://blog.cognitect.com/blog/2016/7/26/clojure-spec-screencast-testing
new screencast about check and instrument
Are there any thoughts on using spec for something like web form validation? Specifically having some way to generate user-readable messages from failed predicates, i.e. more fine-grained than "Name is wrong"
(I don't have much experience with spec, apologies if this is either a really frequent question or a really stupid one.)
@jonathanj: IMO, the output would be okay for parsing for a web form. However, spec doesn't play too well with cross validation, e.g. "is this email taken in the database?"
I also found specifying equal fields difficult, with meaningful output, so you'd have a few special cases to handle outside of s/keys
Are you referring to the error data when you say output, @dominicm? I don't see how the error data would be suitable for a user-facing form, you need a layer of translation since arbitrary predicate names are unlikely to be of value to users in most circumstances.
@dominicm: what about involving multiple values in a validation? We have a case where the SSN needs to be validated against the gender of the selected title (don't ask), would this be written as a separate spec that combines the others, with and
perhaps?
And perhaps more interestingly, would the error data allow me to determine all the participants in the failing validation?
User forms have plenty of awkward cases, domain logic runs rampant here.
I think and would be appropriate yes. You want to ensure the SSN, gender and selected title are all valid before doing the overall validation I assume? That would be s/and
.
I don't know the api too well though, my interest dwindled when I tried to use spec for web forms and found limitations in spec.
I did find that the output error data was very thorough though, and you could derive a lot of information from it.
@dominicm: You're quite right about awkward cases for user forms, did you go another route in the end?
https://github.com/logaan/vlad I can highly recommend vlad though.
I've already written two (JS) validation libraries and they are plagued with reinventing existing predicates. I was hoping to find a better way of layering this on something else.
vlad has a lot of useful predicates built in. https://github.com/weavejester/valip/blob/master/src/valip/predicates.clj I sometimes take advantage.
My experience was that a Boolean is not a good enough result for explaining errors to users, but having to decompose the data after the predicate failed was too much duplication of effort
https://github.com/logaan/vlad/blob/master/src/vlad/core.cljc#L117 this is the definition of the present?
checker
@bsima: Which version of Clojure? That works for me on Alpha 10.
lein clean
solves so many evils 😈
@gfredericks: Just following up real quick on that issue last week where explicit loading of test.check and clojure.spec.test/check
lead to MultiFn errors. You mentioned master
seemed to fix it. Any thoughts on when the next release will be cut?
Probably depends on whether it's still painful for @alexmiller
@dominicm: interesting, didn't know about vlad, looks cool
@kendall.buchanan: I'll prioritize getting a good release together ASAP
@gfredericks: Thank you. I don’t mean to put pressure on you, or anything, but I do sure appreciate it.
No worries
I’m willing to do a release, just would prefer to do as few as possible as it will take me at least an hour to figure out how again
@gfredericks: a good change log wrt to things likely to affect spec would also be helpful to have
@alexmiller: like to send to you folks or for permanent public consumption?
public, not looking for anything special for us, just to have a place to start analyzing impact