Fork me on GitHub
#clojure-spec
<
2021-12-20
>
wilkerlucio20:12:28

hello, is there a place that explains how to properly implement the s/Spec protocol? I'm not sure about some of the methods, also, is there a place that explains the :path, :via and :in parts of the spec problems? (I see in the spec docs it talks about but doesn't mention exact those keys)

Alex Miller (Clojure team)20:12:47

No, we don't really consider that public api

Alex Miller (Clojure team)20:12:29

But if you have a question I'll try to answer it :)

wilkerlucio21:12:08

mostly about the :path, :via and :in, what is expect on each and what makes it different from one another?

Alex Miller (Clojure team)22:12:58

although those are words in the error message that map to the keys: • :path - vector of keyword tag "path" segments (usually from :or, :cat, :alt, etc) • :via - vector of spec names from the root • :in - vector of data values from root to failing value (will be omitted if it's the root value)

Alex Miller (Clojure team)22:12:07

there's an implicit tree being recursively walked here. the nodes are specs (name = :via element). Each edge has a name (:path element) and the value to validate (:in element)

Alex Miller (Clojure team)22:12:46

in some cases, some of those are synthetic, created by the spec

wilkerlucio22:12:08

the examples I'm seeing are mostly related to s/keys, where I see things like this:

(s/def ::a string?)

(s/explain-data (s/keys :req [::a]) {::a 1})

{:clojure.spec.alpha/problems ({:path [:com.piposaude.model.bulk-insert-test/a],
                                :pred clojure.core/string?,
                                :val 1,
                                :via [:com.piposaude.model.bulk-insert-test/a],
                                :in [:com.piposaude.model.bulk-insert-test/a]}),
 :clojure.spec.alpha/spec #object[clojure.spec.alpha$map_spec_impl$reify__1998
                                  0xabd19ae
                                  "clojure.spec.alpha$map_spec_impl$reify__1998@abd19ae"],
 :clojure.spec.alpha/value {:com.piposaude.model.bulk-insert-test/a 1}}

wilkerlucio22:12:20

in this case all :path, :via and :in are the same value

wilkerlucio22:12:58

but from what I got to you, is like: :in - path from root :path - local path :via - specs in the process is that a fair simplification of them?

wilkerlucio22:12:31

and do you have examples that can clear up the distinction?

Alex Miller (Clojure team)17:12:22

they are all "paths", but :in is data, :path is tags, and :via is specs