Fork me on GitHub
#clojure-spec
<
2018-10-12
>
ikitommi05:10:56

@basti there are two options: use ds/or or convert data-specs into normal clojure.specs and use s/or:

(ds/or
  {:200 {:status (s/spec #{200})
         :success boolean?
         :body {:data [{:id string?}]}}
   :500 {:status (s/spec #{500})
         :success boolean?
         :body empty?}})

(s/or :200 (ds/spec
             {:name ::200
              :spec {:status (s/spec #{200})
                     :success boolean?
                     :body {:data [{:id string?}]}}})
      :500 (ds/spec
             {:name ::500
              :spec {:status (s/spec #{500})
                     :success boolean?
                     :body empty?}}))

basti15:10:54

that awesome thanks for your help --appreciated!

Charles Fourdrignier12:10:23

After solving Infix Calculator on 4Clojure (http://www.4clojure.com/problem/135), I would like to write some spec for the args.

(s/def ::infix-args
    (s/cat :a int? 
            :rest (s/* 
                    (s/cat :f #{+ - / *} :b int?))))
Do you see a better way to do that ?

taylor12:10:31

looks fine to me

taylor12:10:01

I suppose you could use number? instead of int?