This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-11
Channels
- # announcements (1)
- # aws (2)
- # beginners (140)
- # boot (67)
- # cider (50)
- # clojure (64)
- # clojure-berlin (1)
- # clojure-conj (1)
- # clojure-france (2)
- # clojure-italy (2)
- # clojure-nl (8)
- # clojure-norway (6)
- # clojure-seattle (1)
- # clojure-spec (81)
- # clojure-sweden (2)
- # clojure-uk (131)
- # clojurescript (147)
- # clojutre (7)
- # cursive (40)
- # datomic (34)
- # editors (5)
- # emacs (7)
- # events (9)
- # figwheel (18)
- # figwheel-main (1)
- # fulcro (2)
- # instaparse (1)
- # jobs (3)
- # leiningen (1)
- # luminus (10)
- # lumo (1)
- # mount (6)
- # off-topic (12)
- # pedestal (4)
- # portkey (7)
- # re-frame (8)
- # reagent (21)
- # reitit (10)
- # ring-swagger (5)
- # shadow-cljs (140)
- # specter (4)
- # tools-deps (53)
- # uncomplicate (1)
Sorry if this is a faq, but I’d like to generate specs at runtime to use for validation eg:
In order to know how to validate this thing, I’d need to look up what the model is in a database, and then construct a spec based on that model.
And with my understnading of spec, this is not possible, but I’d like to flag it as a use case, just in case.
I know that there seems to be some disinclination to adding more support this. it’s my most-desired feature
@ghadi but my specs are not “known” or stored anywhere, and there might be a bunch of models (a bunch being in the thousands).
While I’m typing this, I guess I think that if specs were data, this would be feasible, right?
the ability to have “anonymous” specs / specs-as-data would have a lot more utility as a general purpose way of describing data. but I think that it rubs against the desire of the core team to encourage people to use namespaced keys
regardless of the mechanism, your specs have to be known somehow if you want to dynamically load them
any validation system that stores stuff as data needs to convert list-of-strings
into some predicate
Yeah, I see that, list-of-strings
which is one of a few predefined types, would be mapped to (s/coll-of string?)
there’s also https://github.com/metosin/spec-tools which might be a more ergonomic solution
with spec-tools, without macros, on top of the non-documented parts of clojure.spec:
(require '[spec-tools.data-spec :as ds])
(require '[clojure.spec.alpha :as s])
(let [model {:foo integer?
:bar [string?]
:baz string?}
spec (ds/spec
{:spec model
:name ::spec})]
(s/valid? spec {:foo 1
:bar ["kikka" "kukka"]
:baz "abba"}))
; true
@borkdude yes, it is. Quite nice for ad-hoc stuff like web apps, where one would use Schema
https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj
any plans on doing that @alexmiller?
Rich has been getting back to spec and right now I think it’s likely that we’ll try to get 1.10 out the door, then start working on spec in earnest
what are the main features of 1.10? - I saw you were working on better error messages, very nice work
updated JVM/JDK requirements and compatibility, prepl (kind of alpha), error messages
Does that mean we'll get some new tooling from Cognitect based around the prepl?
unlikely for 1.10
whatever you like :0
there’s a bunch of things in work. rather than wait for them all to reach completion, I think we’ll just release 1.10 and keep working on them
The source code? 🙂
I had a quick play with it when it dropped... I can imagine some interesting tooling options based on it...
there’s a small chance it might even be removed before 1.10 releases
it shares many goals with unrepl
both are data-oriented stream repls
We're thinking a bit about building some internal tooling on top of prepl. Automating some of the stuff we currently do today (via a REPL manually).
(we run a Socket Server REPL inside one of our production processes and currently use unrepl to talk to it over an ssh tunnel for certain things)
We used to -- but I didn't like the stack of dependencies that nREPL brought in. Running just a Socket REPL is nicer. And of course we can start any process up with a Socket REPL without needing any code inside the process.
We have a REPL running inside our legacy CFML app so I won't judge 🙂
s/keys
supports and
in :req
, but not :opt
, right? Is there any other way to express “:foo is optional, but if present, :bar must also be present”?
btw, the exact behavior of or
and and
inside s/keys
is still a mystery to me. is there something official to read about it, @alexmiller? or is it all unintended side effect, which should not be relied upon?
@arohner That's usually when I reach for s/and
wrapped around s/keys
and a predicate for the present/not-present relationships...
@seancorfield thanks. The combinations here get a little gnarly to multi-spec, so I guess I’ll punt