This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-19
Channels
- # beginners (59)
- # calva (20)
- # cider (25)
- # clj-kondo (12)
- # cljdoc (3)
- # cljsrn (15)
- # clojure (104)
- # clojure-europe (4)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-spec (14)
- # clojure-uk (13)
- # clojurescript (33)
- # code-reviews (26)
- # core-async (1)
- # cursive (5)
- # data-science (3)
- # datomic (8)
- # emacs (3)
- # fulcro (5)
- # graphql (3)
- # hoplon (1)
- # jobs-discuss (4)
- # kaocha (14)
- # nyc (1)
- # off-topic (33)
- # pathom (4)
- # pedestal (2)
- # quil (1)
- # re-frame (5)
- # reagent (10)
- # reitit (6)
- # rewrite-clj (3)
- # shadow-cljs (173)
- # specter (7)
- # sql (4)
- # vim (58)
- # yada (3)
This seems to work:
(s/def ::entry (s/or :project (s/cat :file string? :data ::project)
:profiles (s/cat :key (s/and keyword? #(= (name %) "profiles"))
:data (s/coll-of string? :kind vector?))))
(s/def ::projects (s/coll-of ::entry :kind map?))
@cfleming there's a support for closed maps in spec-tools
(https://github.com/metosin/spec-tools/blob/master/CHANGELOG.md#092-alpha1). Also I posted my take a while back: https://gist.github.com/metametadata/53a847cd3b02056e8e4c124e63d9ae5a.
@metametadata Thanks! I’ll try yours out since it looks like the error messages might be more helpful.
cool! we use an evolved version in company projects (which e.g. is more convoluted because of https://github.com/metosin/compojure-api/issues/417), but didn't have time to publish it yet
I’m trying to write a spec for a payload wrapper map.
For simplicity, the spec I’m trying to write is for a map with two keys, :query
and :payload
.
For the purposes of this example, I’m using extremely simple examples of the payload with just maps of one key.
`
(s/def ::query (and keyword? #{:avalue :anothervalue :thirdvalue}))
(s/def ::email string?)
(s/def ::user-id integer?)
(s/def ::avalue (s/keys :req-un [::email]))
(s/def ::anothervalue (s/keys :req-un [::user-id]))
{:query :avalue
:payload {:email “<mailto:[email protected]|[email protected]>” }}
{:query :anothervalue
:payload {:user-id 123}}
`
I can use multi-spec and a defmulti to key off the :query object,
but that doesn’t let me use the shared :payload
keyword. Is the only way around this to define ::avalue and ::anothervalue in different namespaces ::avalue/payload ::anothervalue/payload? I haven’t created a lot of namespaced keywords in clojure yet.
yes, you would need to use different namespaces in this case
the ::query spec is redundant btw, just (s/def ::query #{:avalue :anothervalue :thirdvalue}) would be sufficient
Do I need to create a separate valid namespace, or can I define the specs with a a namespace that doesn’t correspond to an existing clojure file? ie, does there need to be a (ns anothervalue)
somewhere before I can do a (s/def ::anothervalue/payload string?)
which may correspond to an actual namespace, but doesn't have to
you can use a keyword with any qualifier
a lot of docs in Clojure are not particularly clear on this point