This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-21
Channels
- # announcements (13)
- # babashka (63)
- # babashka-sci-dev (64)
- # beginners (37)
- # biff (1)
- # calva (10)
- # cider (7)
- # clj-kondo (15)
- # cljsrn (6)
- # clojure (26)
- # clojure-dev (10)
- # clojure-europe (34)
- # clojure-france (9)
- # clojure-nl (2)
- # clojure-norway (36)
- # clojure-uk (5)
- # clojurescript (142)
- # community-development (1)
- # conjure (3)
- # datalevin (5)
- # datalog (2)
- # datomic (5)
- # events (11)
- # fulcro (40)
- # gratitude (9)
- # guix (32)
- # honeysql (10)
- # jobs (2)
- # lsp (32)
- # malli (15)
- # meander (5)
- # membrane (43)
- # missionary (3)
- # nextjournal (9)
- # off-topic (38)
- # pathom (3)
- # polylith (30)
- # portal (78)
- # programming-beginners (4)
- # quil (6)
- # re-frame (20)
- # reagent (21)
- # remote-jobs (2)
- # shadow-cljs (7)
- # tools-deps (6)
- # xtdb (23)
Hello! Is it possible to use malli with compojure + swagger? Couldn’t find any examples. I can only see an option to implement the protocol Coercion
Is it related to some kind of restrictions? I’m a little surprised since compojure-api as well retitit and malli are created by metosin :)
> I have a hack to turn a malli spec into a Schema, if that helps Yes, could you show me an example?
I haven’t tested that on a compojure-api route yet, but here’s the gist of it:
(require '[schema.core :as schema]
'[schema.spec.core :as schema.spec]
'[schema.spec.leaf :as leaf])
(defn malli->schema [malli-schema]
(reify schema/Schema
(spec [this]
(leaf/leaf-spec
(schema.spec/precondition this
(fn [data]
(m/validate malli-schema data))
(fn [data]
(me/humanize (m/explain malli-schema data))))))
(explain [this]
(str "Malli->Schema:" malli-schema))))
but this allows you to use schema like this:
(schema/check
(malli->schema [:map [:foo int?] [:bar keyword?]])
{:foo 1 :bar 2})
=> (not {:bar ["should be a keyword"]})
(schema/check
(malli->schema [:map [:foo int?] [:bar keyword?]])
{:foo 1 :bar :humbug})
not perfect, and I’m about to use this in :body
and :path-params
and see if that works
is it possible to get the current index of a vector spec, so that I can have different validation logic for the exact nth element?
ok, but it’s a bit clumsy if the validation of a specific item share most but just varies a little bit from the other…… thx a lot for your prompt respond anyway :man-bowing::skin-tone-2: