malli

https://github.com/metosin/malli :malli:
bartuka 2021-03-02T01:41:56.113300Z

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?

bartuka 2021-03-02T01:51:34.113700Z

I think https://github.com/metosin/malli/blob/a58e04b265b1b6658bb9fe791fd103cfab452e53/src/malli/core.cljc#L1873 (sequence-schemas) happened after the last release hehe

2021-03-02T02:30:01.113900Z

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

👍 1
Yevgeni Tsodikov 2021-03-02T08:12:31.117400Z

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

👍 1
Yevgeni Tsodikov 2021-03-02T09:39:30.118700Z

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 Tsodikov 2021-03-02T09:41:20.118900Z

(mu/merge 
  [:map [:specific-field string?]]
  [:and
   [:map [:x int?] [:y int?]]])
=> [:and [:map [:x int?] [:y int?]]]

ikitommi 2021-03-02T09:44:36.119100Z

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:

ikitommi 2021-03-02T09:45:24.119300Z

need to check would it break existing contracts or not.

ikitommi 2021-03-02T09:47:00.119500Z

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

Yevgeni Tsodikov 2021-03-02T09:47:52.119700Z

That would be great!

Yevgeni Tsodikov 2021-03-02T09:50:05.119900Z

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

👌 1
ikitommi 2021-03-02T12:06:14.121700Z

[metosin/malli "0.3.0"] 🥳 🥳 🥳

🎉 9
2021-03-02T12:40:33.129900Z

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

ikitommi 2021-03-02T13:02:26.130700Z

I see. PR would be welcome to fix this. Maybe stringify all reference keys?

2021-03-02T13:05:23.130900Z

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

👍 1
ikitommi 2021-03-02T13:14:17.131100Z

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

2021-03-02T13:14:45.131400Z

cool, will be back with PR )

stathissideris 2021-03-02T14:08:36.132100Z

congrats on the release!

👍 1
🎉 1