This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-14
Channels
- # announcements (3)
- # asami (22)
- # babashka (9)
- # beginners (92)
- # calva (7)
- # clj-kondo (8)
- # clojure (61)
- # clojure-australia (3)
- # clojure-boston (1)
- # clojure-dev (3)
- # clojure-europe (24)
- # clojure-nl (3)
- # clojure-spec (4)
- # clojure-uk (14)
- # clojurescript (5)
- # conjure (12)
- # core-async (44)
- # cryogen (8)
- # crypto (2)
- # cursive (24)
- # data-science (5)
- # events (1)
- # fulcro (10)
- # garden (2)
- # graalvm (19)
- # helix (4)
- # instaparse (13)
- # lsp (13)
- # luminus (1)
- # malli (5)
- # meander (22)
- # off-topic (22)
- # polylith (8)
- # re-frame (69)
- # react (1)
- # reagent (2)
- # releases (2)
- # shadow-cljs (52)
- # sql (7)
- # test-check (3)
- # timbre (2)
- # tools-deps (9)
Hi, I know spec2 is still in alpha/experimental phase and buggy. Still, I have been playing around with it to model the domain of an experimental project I have, where I want to test out the capabilities of domain modelling with schema/select. Is it possible to have a multi-spec return a schema, and do select on the multi-spec? It doesn’t seem to work on current git-sha, I wonder if it’s a bug or is it intended that this is not possible:
(spec/def :account/id string?)
(spec/def :service/id string?)
(spec/def :service-1/field string?)
(spec/def :service-2/field string?)
(defmulti account-schema :service/id)
(defmethod account-schema :service-1
[_]
(spec/schema [:account/id :service-1/field]))
(defmethod account-schema :service-2
[_]
(spec/schema [:account/id :service-2/field]))
(spec/def :account/account (spec/multi-spec account-schema :service/id))
(gen/generate (spec/gen :account/account))
(spec/valid? (spec/select :account/account [:account/id :service-1/field :service/id])
{:service/id :service-1
:account/id "id#1"
:service-1/field "abcd"})
The generator works correctly, but not the validation, that fails with:
; Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval5667$fn$G (protocols.clj:20).
; No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.alpha.spec.impl$multi_spec_impl$reify__7055
undecided stuff in this area about what can act as a schema provider
if you have a use case where this would be useful, would be helpful to have an https://ask.clojure.org question with request
tag