metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
592 stars 94 forks source link

Top level data spec not in registry #142

Closed arichiardi closed 5 years ago

arichiardi commented 6 years ago

Hello folks!

It seems like the registration of data spec with ds/spec has stopped working, will write the versions I am using at the bottom and I am open to try things out.

Example:

(def command-spec
  (ds/spec
   {:name ::command
    :spec {:domain string?
           :entity string?
           :name string?}}))

cljs.user> (s/explain-str ::command {:foo "Bar"})
.../.shadow-cljs/builds/az/dev/out/cljs-runtime/cljs.spec.alpha.js:188
throw (new Error(["Unable to resolve spec: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k)].join('')));
^

Error: Unable to resolve spec: :...policy/command

In the registry I see only the following but not the top level specified by ::name:

cljs.user> (filter #(re-find #"policy.command" (str %)) (keys (s/registry)))
(:...policy$command/name
 :...policy$command/domain
 :...policy$command/entity)

Versions:

org.clojure/clojure {:mvn/version "1.10.0-alpha8"}
org.clojure/clojurescript {:mvn/version "1.10.339"}
metosin/spec-tools {:mvn/version "0.8.0"}

Thanks folks!

arichiardi commented 6 years ago

I have also tried in a vanilla REPL against latest ClojureScript and I get the same behavior

cljs.user=> (s/valid?
       #_=>   ::person
       #_=>   {::age 63
       #_=>    :boss true
       #_=>    :name "Liisa"
       #_=>    :languages #{:clj :cljs}
       #_=>    :aliases [{:alias "Lissu"} "Liisu"]
       #_=>    :orders [{:id 1, :description "cola"}
       #_=>             {:id 2, :description "kebab"}]
       #_=>    :description "Liisa is a valid boss"
       #_=>    :address {:street "Amurinkatu 2"
       #_=>              :zip "33210"}})
Error: Unable to resolve spec: :cljs.user/person
     cljs$spec$alpha$reg_resolve_BANG_ (.cljs_nashorn_repl/cljs/spec/alpha.cljs:71:11)
     cljs$spec$alpha$Specize$specize_STAR_$arity$1 (.cljs_nashorn_repl/cljs/spec/alpha.cljs:136:18)
     cljs$core$IFn$_invoke$arity$1 (.cljs_nashorn_repl/cljs/spec/alpha.cljs:131:1)
     cljs$spec$alpha$specize_STAR_ (.cljs_nashorn_repl/cljs/spec/alpha.cljs:131:1)
     cljs$core$IFn$_invoke$arity$1 (.cljs_nashorn_repl/cljs/spec/alpha.cljs:160:24)
     cljs$spec$alpha$specize (.cljs_nashorn_repl/cljs/spec/alpha.cljs:159:1)
     cljs$core$IFn$_invoke$arity$2 (.cljs_nashorn_repl/cljs/spec/alpha.cljs:374:4)
     cljs$spec$alpha$valid_QMARK_ (.cljs_nashorn_repl/cljs/spec/alpha.cljs:371:1)
     (<NO_SOURCE_FILE> <eval>:1:0)
     (<NO_SOURCE_FILE> <eval>:1:0)
     (<NO_SOURCE_FILE> <eval>:1:0)
ikitommi commented 5 years ago

Hi. This is intentional, ds/spec works like s/spec and doesn't register the spec. See: https://github.com/metosin/spec-tools/issues/66#issuecomment-313330951.

End goal is to allow fully anonymous data-specs, see #55.

arichiardi commented 5 years ago

Oh that's too bad but I see the point, thanks for redirecting to the right issue!