clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Charlie Briggs 2020-07-17T10:58:53.002400Z

hello, we’ve recently started using specs and have a few questions regarding how to load them correctly say we have a namespace identity-provider and wish to have specs for identity-providers in a s_eparate file_, how would we go about doing that? We’re looking at putting the actual specs into a separate namespace as otherwise we’re having cycling import issues if we put our specs in a separate file/namespace (say specs.core, and named them as :core.identity-provider/id, :core/identity-provider would we need to then require :refer :all in consumer namespaces to ensure they’re loaded? Would it be more sensible to have a separate file for each entity specs, e.g. specs.identity-providers ? How would the ‘root’ object for the identity-provider look in that case (rather than using the name :core/identity-provider )

👀 1
seancorfield 2020-07-17T15:41:54.003300Z

You don't need to refer specs. Just requiring the namespace they're in will cause them all to be registered.

seancorfield 2020-07-17T15:43:05.004500Z

It's common to put data-describing specs in a separate namespace from code. As long as you require that spec namespace somewhere (anywhere, early in your execution path), those specs will then become globally available.

Charlie Briggs 2020-07-20T08:31:28.009400Z

thanks for your response, so would it be common practise to load all specs in the server entrypoint, or a user.clj dev-namespaced file for use in the repl, rather than loading them in the code which is using them?

seancorfield 2020-07-17T15:43:13.004700Z

@charliebriggs ^

Daniel Stephens 2020-07-17T15:52:21.008300Z

I don't know if this is at all good practice, but we have a ns per 'entity' for our specs to keep things readable, specs in one namespace can refer to others outside of their namespace by using fully qualified keywords (as normal), and then we have one ns which just requires them all. Those are all package together as one dependency, then anything that wants to use them just imports the dependency and requires that one namespace.

1