Fork me on GitHub
#malli
<
2021-03-02
>
bartuka01:03:56

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?

mynomoto02:03:01

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

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

👍 1
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

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

ikitommi09:03:36

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:

ikitommi09:03:24

need to check would it break existing contracts or not.

ikitommi09:03:00

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 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.

👌 1
ikitommi12:03:14

[metosin/malli "0.3.0"] 🥳 🥳 🥳

🎉 9
delaguardo12:03:33

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&amp;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

ikitommi13:03:26

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

delaguardo13:03:23

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

👍 1
ikitommi13:03:17

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

delaguardo13:03:45

cool, will be back with PR )

stathissideris14:03:36

congrats on the release!

👍 1
🎉 1