This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-02
Channels
- # announcements (9)
- # babashka (67)
- # beginners (62)
- # bitcoin (2)
- # clara (1)
- # clj-kondo (62)
- # cljfx (6)
- # cljs-dev (25)
- # clojars (17)
- # clojure (142)
- # clojure-australia (2)
- # clojure-europe (42)
- # clojure-gamedev (2)
- # clojure-nl (31)
- # clojure-poland (10)
- # clojure-spec (14)
- # clojure-uk (30)
- # clojurescript (3)
- # conjure (1)
- # cursive (10)
- # data-science (1)
- # datascript (4)
- # datomic (9)
- # depstar (7)
- # fulcro (17)
- # girouette (15)
- # graalvm (44)
- # honeysql (20)
- # jackdaw (3)
- # jobs (8)
- # jobs-discuss (10)
- # juxt (5)
- # lein-figwheel (1)
- # lsp (175)
- # malli (19)
- # pedestal (2)
- # reagent (31)
- # reitit (2)
- # remote-jobs (3)
- # reveal (12)
- # sci (77)
- # shadow-cljs (22)
- # specter (6)
- # startup-in-a-month (2)
- # tools-deps (1)
- # xtdb (21)
I am trying to use :*
and got this message {:type :malli.core/invalid-schema, :data {:schema :*}}
there is some setup to enable regex-like support?
I think https://github.com/metosin/malli/blob/a58e04b265b1b6658bb9fe791fd103cfab452e53/src/malli/core.cljc#L1873 (sequence-schemas) happened after the last release hehe
Hi all,
I’m trying to define a map with several optional fields, that at least 1 of them must exist.
For example, :a
and :b
are optional, :c
is required.
{:a 1 :c 1} ; valid
{:b 1 :c 1} ; valid
{:a 1 :b 1 :c 1} ; valid
{:c 1} ; nope, invalid
As a reference, with `spec` , I’d write something like
(s/def ::my-map
(s/keys :req-un [::c (or ::a ::b)]))
@evg.tso you can compose with :and
, see example here: https://malli.io/?value=%7B%3Ax%201%2C%20%3Ay%202%7D&schema=%5B%3Aand%0A%20%5B%3Amap%20%5B%3Ax%20int%3F%5D%20%5B%3Ay%20int%3F%5D%5D%0A%20%5B%3Afn%0A%20%20%7B%3Aerror%2Fmessage%20%22x%20should%20be%20greater%20than%20y%22%7D%0A%20%20(fn%20%5B%7B%3Akeys%20%5Bx%20y%5D%7D%5D%20(%3E%20x%20y))%5D%5D
The thing with :and
is that is doesn’t survive mu/merge
very well.
To be more specific, my use case is with reitit
.
There are several routes with common fields, but each route has specific fields that are different from one another.
• POST /share/this
would accept either :a
or :b
and must contain :c
(for example {:a 1 :c 1}
• POST /share/that
would accept either :a
or :b
and must contain :d
(for example {:a 1 :d 1}
.
└── schema with optional fields (at least one must exist)
├── mu/merge-ed schema with specific fields
└── mu/merge-ed schema with specific fields
(mu/merge
[:map [:specific-field string?]]
[:and
[:map [:x int?] [:y int?]]])
=> [:and [:map [:x int?] [:y int?]]]
I see. What if :and
was considered as a constrained-kinda thing, where the first value is the actual schema and the rest are just extra rules for that. Would solve a lot of things. :thinking_face:
would this be more correct:
(mu/merge
[:map [:specific-field string?]]
[:and
[:map [:x int?] [:y int?]]
map?]])
=> [:and [:map [:spesific-field string?] [:x int?] [:y int?]] map?]
That would be great!
In most of my schemas I use :and
to add additional data like a :fn
or a custom error message.
Hi! I’m using malli together with reitit and reitit-swagger and I found a problem when I start using custom malli’s registry. tldr; generated swagger partials for an endpoint contains “definitions” key which is not valid according to swagger2 spec. also it messes up with references trying to point to one of defined schemas. As a workaround I added a middleware to walk throw generated object which will be encoded as json and pull all definitions to the top level but it looks ugly and not generic enough. Also there is a small inconsistency in encoding keywords to json.
https://malli.io/?value=%5B1%20%5B2%20%5B3%20%5B4%20nil%5D%5D%5D%5D&schema=%5B%3Aschema%0A%20%7B%3Aregistry%20%7B%3Afoo%2FConsCell%20%5B%3Amaybe%20%5B%3Atuple%20%3Aint%20%5B%3Aref%20%3Afoo%2FConsCell%5D%5D%5D%7D%7D%0A%20%3Afoo%2FConsCell%5D
here is an illustration — :$ref key contains a string "#/definitions/:foo/ConsCell"
with :
inside. and there is a key :foo/ConsCell
in :definitions
after encoding to json this schema will be invalid because of :
present in “$ref” key
I would like to try ) where such fix should go? reitit-swagger or malli itself?
cool, will be back with PR )