This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-24
Channels
- # aleph (13)
- # announcements (3)
- # beginners (134)
- # calva (9)
- # clojure (33)
- # clojure-europe (19)
- # clojure-nl (2)
- # clojure-norway (42)
- # clojure-uk (7)
- # clojurescript (43)
- # core-async (7)
- # core-typed (2)
- # cursive (32)
- # datomic (19)
- # fulcro (5)
- # gratitude (4)
- # hyperfiddle (26)
- # introduce-yourself (1)
- # jobs-discuss (15)
- # lsp (3)
- # malli (20)
- # off-topic (18)
- # overtone (3)
- # polylith (24)
- # squint (22)
- # xtdb (21)
I think I found a bug regarding Swagger Schema generation: Only definitions from schemas referred to in responses are shown in /definitions
, but those from requests are missing.
Example: With the following route config
:parameters {:body [:map [:company ::validation/company1]]}
:responses {200 {:body ::validation/company2}}
only company2
will be in definitions
(although the ref$
to both def鈥檚 are there).
I looked through the issues on Github and could not find anything related - is this a known issue or should I open a new one?I have submitted https://github.com/metosin/malli/issues/1002
A philosophical question about Malli, and schema checking in general: how much validation is too much? In my application, we have a datomic database wherein entities reference each other with non-component refs. In the maps I'm validating with Malli, these reference attributes have values that look like {:db/id int}
. To only check that the map looks like that (has a :db/id key with an integer value) isn't quite sufficient to know the data is valid - I'd also like to check that the referenced entity is valid to be referenced from this attribute (perhaps by checking the attributes on the referenced entity). I can do this by getting access to a Datomic db
instance in a :fn
schema, and doing arbitrary queries. This leads to my conundrum. Should I do that? Am I setting myself up for problems later? My instinct is to include that validation code but make it conditional on whether or not there's a Datomic db in a *db*
dynamic variable. Perhaps someone can convince me this is a good or bad idea.
I'm leaning towards validating (with Malli) that the entities are of the right shape, but not validate that correctly-shaped identifiers point to valid entities themselves (i.e. exists in a DB).
Thanks for the feedback. I'm going to try out the db query approach and I'll report back in a few months if it turns out I have driven myself insane
This has come up before in this channel, btw. You might want to try a search, in case the past recommendations were more convincing than mine 馃檪
I would recommend against validating for valid/existing data, that will be 1) an incredible performance loss, and 2) harder to test (no generative testing, no stubs, etc)
your integration test suite should cover that ground for you
Is it possible to deref the referenced schema fully with refs as well?
Hmm, that鈥檚 right but if the user could specify max-depth of recursion then the stack would not blow.
But yeah, totally get the rationale! Thank you 馃檹
Hmm, Why in function schema using {:ref "something"} in [:cat] is not allowed.
The error message: :malli.core/potentially-recursive-seqex
. I don't understand why malli suggest the function schema to be potentially recursive in this case 馃槷
sequence schemas inside sequences are inlined - if the :ref
is recursive, it could expand to unlimited sequence:
(def Schema [:cat :int [:ref #'Schema]])
would be expanded like this:
[:cat :int [:ref #'Schema]]
... expanded to ...
[:cat :int :int [:ref #'Schema]]
... expanded to ...
[:cat :int :int :int [:ref #'Schema]]
... expanded to ...
[:cat :int :int :int :int [:ref #'Schema]]
...
you can wrap the :ref
with something like :schema
to mark it just to use one slot in sequence.
from README:
(def Hiccup
[:schema {:registry {"hiccup" [:orn
[:node [:catn
[:name keyword?]
[:props [:? [:map-of keyword? any?]]]
[:children [:* [:schema [:ref "hiccup"]]]]]]
[:primitive [:orn
[:nil nil?]
[:boolean boolean?]
[:number number?]
[:text string?]]]]}}
"hiccup"])
(def parse-hiccup (m/parser Hiccup))
(parse-hiccup
[:div {:class [:foo :bar]}
[:p "Hello, world of data"]])
;[:node
; {:name :div
; :props {:class [:foo :bar]}
; :children [[:node
; {:name :p
; :props nil
; :children [[:primitive [:text "Hello, world of data"]]]}]]}]
Wow. This really works! Thank you!