Fork me on GitHub
#clojure-spec
<
2017-11-27
>
fedreg04:11:19

Is there a way to get spec information similar to how I can use meta to get info on a function? So if I have a spec like (s/def ::example string?) is there some function I can call to see the spec definition? Even better, is there anything that will give me a list of specs in the namespace? Thanks!!!

Alex Miller (Clojure team)15:11:15

yes, you can call (doc ::example)

Alex Miller (Clojure team)15:11:40

you’d have to write something to filter specs per namespace

misha07:11:31

s/registry

ikitommi12:11:25

@taylor related to “similar to swagger” - if specs could be read back from their s/form without eval (I think it could be done already with undocumented part of the spec - but Rich might be doing something functional for this?), we could have a pragmatic subset of specs that could be safely used between servers & clients. and build swagger-like docs for them.

ikitommi12:11:57

we could publish the s/form as vendor extension to the spec-tools swagger-docs. e.f. :x-spec "(clojure.spec/keys :req [:user/x])" + :x-specs on top-level as the spec-registry for the related specs. Non-clojure clients could use swagger/openapi and clojure-clients just the spec-part.

r0man16:11:31

Is this a bug?

r0man16:11:33

(if-let [x false] x :my-ns/invalid) (if-let [x false] x :clojure.spec.alpha/invalid)

r0man16:11:54

the first works, the second raises an exceptions from spec

r0man16:11:00

Call to clojure.core/if-let did not conform to spec: In: [2] val: :clojure.spec.alpha/invalid fails at: [:args :else] predicate: any?

r0man16:11:54

the second form works also in Clojure 1.8

r0man16:11:10

oh, and I was trying the above with Clojure 1.9.0-RC1

qqq17:11:44

is there a way to say: ::foo is a COLLECTION such that (map :get-some-key ...) creates an unique list and if this fails, print out the entire collection

taylor17:11:01

(s/def ::my-map (s/keys :req [::get-some-key]))
(s/def ::my-coll (s/and (s/coll-of ::my-map)
                        #(= (count %)
                            (count (set (map ::get-some-key %))))))
(s/explain ::my-coll [{::get-some-key 1} {::get-some-key 1}])

qqq17:11:48

(as a spec)

fedreg21:11:49

Thanks! Completely missed that registry function.

j-po22:11:05

Is there a minimally ugly way to compare specs from two projects (like two versions of the same codebase)? One idea that comes to mind is loading one set of specs into a separate registry, but that looks like it's been made deliberately hard. Is there maybe a way to blow away the spec registry entirely to restart from scratch?

bfabry22:11:52

specs are fully namespaced with the idea that they'll be unique across projects, so caveat is anything you do that's assuming different is going to end up weird. but, if you want, I'm pretty sure you could just reset! the atom that is the spec registry

gklijs22:11:27

@j-po maybe first load the old one, write all the forms to a map, and serialize. Then start again with the new one, and compare against the stored map?