This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-02
Channels
- # announcements (2)
- # babashka (10)
- # beginners (61)
- # calva (17)
- # cider (27)
- # clj-kondo (14)
- # clojure (230)
- # clojure-austin (4)
- # clojure-europe (17)
- # clojure-france (6)
- # clojure-hungary (3)
- # clojure-norway (30)
- # clojure-sweden (9)
- # clojure-uk (2)
- # clojurescript (58)
- # conjure (11)
- # core-async (7)
- # cursive (74)
- # datalog (2)
- # datomic (15)
- # events (8)
- # figwheel-main (5)
- # fulcro (2)
- # graalvm (23)
- # graphql (2)
- # helix (17)
- # humbleui (2)
- # jobs (2)
- # kaocha (6)
- # lsp (19)
- # malli (7)
- # nbb (51)
- # off-topic (33)
- # pathom (26)
- # pedestal (2)
- # polylith (1)
- # portal (4)
- # re-frame (17)
- # react (3)
- # reitit (5)
- # releases (2)
- # remote-jobs (2)
- # shadow-cljs (18)
- # sql (65)
- # tools-deps (8)
- # xtdb (28)
Is there a way to use a schema which has few maybe schemas but consider maybe not be there for validation? Or do I have to strip the maybes from schema and do validation manually? On mobile, I can give code sample later if needed.
ok case is like this.
1. I've got a few endpoints (around 20) returning large sets of xml. These are quite old services that we don't have control over.
2. I parse xml, then do some transformations on them
3. I have malli schemas for the transformed data. I coerce the data using schemas. Then I validate using same schemas.
4. Data from the services are often incomplete (nil values where they shouldn't be mostly). So I add [:maybe ...]
for some fields to sort of make the validations work.
5. Now, I'd like to still know the cases where validations fail without the [:maybe ...]
wrappings so I can have a report of missing stuff. Is it possible to do this or do I have to transform schema myself and remove the [:maybe ...]
wrappings?
sample:
(def counterparties-schema
[:vector
[:map
[:address [:maybe :string]]
[:baseNumber :int]
[:contactName [:maybe :string]]
[:contactPhone [:maybe :string]]
[:cptyType [:maybe :string]]
[:enabledForSettlement :boolean]
[:id :int]
[:legalVehicleId :int]
[:mnemonic :string]
[:name [:maybe :string]]]])
;; Validation with this succeeds
(m/validate counterparties-schema data)
=> true
;; But I'd still like to know fields where validation would have failed if [:maybe ...] wrappings weren't there.
;; i.e [:address :string] etc.
;; Manually something like this:
(defn strict [schema]
(clojure.walk/postwalk
(fn [v]
(if (and (vector? v) (= (first v) :maybe))
(second v) v))
schema))
;; So I can still know the missing values
(m/validate (strict counterparties-schema) data)
What I was asking first is that is this kind of thing supported by malli itself? Perhaps that's a dumb question.
Is this a common use case though? Or am I thinking about this wrong?CLJS instrumentation reloading discussion in #clojurescript https://clojurians.slack.com/archives/C03S1L9DN/p1667377689417939?thread_ts=1667373586.775569&cid=C03S1L9DN
A question about decompleted map keys and values: if I register, for example, that :user/id
is always an [:string {:min 1}]
, is there a way to query Malli for :user/id
and know the result is [:string {:min 1}]
? Or even if it's just a :string
?
(m/schema :user/id)
returns the ref, you can deref that with m/deref
(or m/deref-all
)
Thanks, I had to do one step further to be useful:
(m/ast (m/deref-all (m/schema :user/id)))
That helped 🙂