Fork me on GitHub
#clojure-spec
<
2019-05-26
>
y.khmelevskii14:05:30

Hi everyone! Can you please explain me why this spec doesn’t work correctly:

(s/def ::name string?)
(s/def ::src string?)
(s/def ::width pos-int?)
(s/def ::height pos-int?)

(s/def ::size
  (s/schema {:src    ::src
             :width  ::width
             :height ::height}))

(s/def ::file
  (s/select
   (s/schema {:name ::name
              :size  ::size})
   [:name :size {:size [*]}]))

(s/valid? ::file {:name "test"
                  :size {}})
;; => true
;; but should be false

y.khmelevskii14:05:01

but when I use fully-qualified keywords, s/valid? works correctly

seancorfield20:05:47

@y.khmelevskii I tried the following and it also produces true

user=> (s/def ::file (s/select (s/schema {:name ::name :size ::size}) [:name :size {:size [:src :width :height]}]))
:user/file
user=> (s/valid? ::file {:name "x" :size {}})
true
I'm not sure what restrictions are in place for unqualified key usage. It is all alpha, after all.

benzap23:05:51

Has clojure.spec 2.0 landed already, or is it still in the development stage?

seancorfield23:05:02

Very much alpha at the moment @benzap

seancorfield23:05:32

There hasn't even been an "alpha" release yet -- it's just on GitHub.