This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-01
Channels
- # adventofcode (93)
- # announcements (44)
- # asami (23)
- # aws (1)
- # babashka (48)
- # beginners (112)
- # calva (26)
- # cider (57)
- # clj-kondo (17)
- # cljfx (5)
- # cljs-dev (21)
- # clojure (124)
- # clojure-europe (19)
- # clojure-hungary (40)
- # clojure-nl (3)
- # clojure-spec (7)
- # clojure-uk (3)
- # clojurescript (3)
- # cursive (81)
- # datalog (11)
- # events (21)
- # exercism (1)
- # fulcro (37)
- # graalvm (1)
- # introduce-yourself (8)
- # jobs (1)
- # lsp (1)
- # malli (5)
- # membrane-term (17)
- # minecraft (3)
- # nextjournal (5)
- # off-topic (14)
- # other-lisps (14)
- # polylith (58)
- # reagent (16)
- # reclojure (3)
- # reitit (6)
- # remote-jobs (1)
- # shadow-cljs (55)
- # spacemacs (15)
- # testing (2)
- # tools-build (7)
- # tools-deps (191)
yea, i had a few of those too but since these are registered "globally" they're fair game to my (spec-based) fuzzer. so, i'm making the ones in my project "defensive" against this (although it should never happen from production code)
i.e., this is where the inputs are coming from (with the one exceptional case i've found [which crashes] excluded):
(s/cat :spec (s/with-gen qualified-keyword? #(gen/elements
(clojure.set/difference
(set (keys (s/registry)))
#{::s/kvs->map})))
:val any?)
Hello! I made a function to return specs depending on arguments.
(defn- search-schema-spec-for-of-and-defaultValue [of defaultValue]
(s/keys :req-un [:build-api.search-schema/key
of
:build-api.search-schema/valueType
:build-api.search-schema/cardinality]
:opt-un [:build-api.search-schema/of
defaultValue
:build-api.search-schema/doc]))
It’s called like the following,
(search-schema-spec-for-of-and-defaultValue
:build-api.search-schema.listing/scope :build-api.search-schema.enum.one/defaultValue)
But I get the following error
Unexpected error (AssertionError) macroexpanding s/keys at (src/sharetribe/build_api/routes.clj:136:3).
Assert failed: all keys must be namespace-qualified keywords
(every? (fn* [p1__1917#] (c/and (keyword? p1__1917#) (namespace p1__1917#))) (concat req-keys req-un-specs opt opt-un))
I just wanna factor out common parts and make different specs based on of
and defaultValue
as they are the differentiator, any advice on how to achieve?Thanks! @U47G49KHQ
I defined common spec separately and combined with s/and
and this seems to work good enough for me!
(def build-api-search-schema-common-spec
(s/keys :req-un [:build-api.search-schema/key
:build-api.search-schema/valueType
:build-api.search-schema/cardinality]
:opt-un [:build-api.search-schema/of
:build-api.search-schema/doc]))
(s/and build-api-search-schema-common-spec (s/keys :req-un [:build-api.search-schema.listing/scope]
:opt-un [:build-api.search-schema.enum.one/defaultValue]))
...etc...
Thanks