Fork me on GitHub

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?


If you are using tools-deps you can reference a github commit.

👍 3
Yevgeni Tsodikov08:03:31

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)]))

👍 3
Yevgeni Tsodikov09:03:30

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

Yevgeni Tsodikov09:03:20

  [:map [:specific-field string?]]
   [: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:


need to check would it break existing contracts or not.


would this be more correct:

  [:map [:specific-field string?]]
   [:map [:x int?] [:y int?]]
=> [:and [:map [:spesific-field string?] [:x int?] [:y int?]] map?]

Yevgeni Tsodikov09:03:52

That would be great!

Yevgeni Tsodikov09:03:05

In most of my schemas I use :and to add additional data like a :fn or a custom error message.

👌 3

[metosin/malli "0.3.0"] 🥳 🥳 🥳

🎉 27

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.;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 see. PR would be welcome to fix this. Maybe stringify all reference keys?


I would like to try ) where such fix should go? reitit-swagger or malli itself?

👍 3

In malli, either malli.json-schema or malli.swagger ns.


cool, will be back with PR )


congrats on the release!

👍 3
🎉 3