malli

https://github.com/metosin/malli :malli:
2021-05-20T09:05:53.021600Z

Hi! Is Malli a good candidate to use for server side form validation in replacement for lib like https://funcool.github.io/struct/latest/? Especially thanks to malli.error / humanize?

2021-05-20T09:10:35.022700Z

With some hand made regex validators (email, etc) like https://github.com/funcool/struct/blob/master/src/struct/core.cljc#L195 + locale support, I think so, right?

ikitommi 2021-05-20T09:50:28.023500Z

@admin055 definetely

2021-05-20T09:54:28.025100Z

Perfect, thanks for the confirmation. I'll toy with Malli in a project and see how to organize this. 👍

2021-05-20T09:55:42.025300Z

is there an example demo project with form validation somewhere?

2021-05-20T09:59:01.026200Z

I like very much the Reitit's example folder, if my tests are successful after a code review, I may be able to contribute with an example PR with form validation on Malli's Github.

2021-05-20T09:59:41.026500Z

What do you think?

ikitommi 2021-05-20T10:00:47.027500Z

sure, examples welcome! I have a malli-form (reagent) demo draft, but nothing serious.

2021-05-20T10:02:15.027700Z

Perfect, let's do this!

dharrigan 2021-05-20T10:07:50.027900Z

<https://github.com/dharrigan/startrek> has form validation

dharrigan 2021-05-20T10:08:01.028100Z

<https://github.com/dharrigan/startrek/blob/master/src/startrek/base/api/starship/specs.clj>

dharrigan 2021-05-20T10:08:19.028300Z

used here <https://github.com/dharrigan/startrek/blob/master/src/startrek/base/api/starship/routes.clj>

2021-05-20T10:10:21.028600Z

Awesome, thanks @dharrigan!

dharrigan 2021-05-20T10:10:31.028800Z

you're most welcome

👍 2
2021-05-20T16:18:33.030800Z

hi, Anyone know if Malli has support that allows you to set a default value if the value doesn't pass the schema check?

dharrigan 2021-05-20T16:20:28.031Z

You mean this? <https://github.com/metosin/malli#default-values>

2021-05-20T16:21:19.031200Z

possibly. Generally I just want to check a map is valid but keep any good values and log out any errors

2021-05-20T16:33:00.031500Z

looks like that just sets a default if the value is missing:

(m/parse
 [:and {:default 42} int?]
 "test");; =&gt; :malli.core/invalid


(m/decode [:and {:default 42} int?]
          "test"
          mt/default-value-transformer);; =&gt; "test"
I'll probably just use m/explain and do something based on if there are errors

Vladislav 2021-05-20T18:35:10.034100Z

hi! Deref of [:merge ...] makes :registry with nested schemas of one of merged schemas invisible (but it still works). is it a bug, or feature, or there is some workaround Im missing? point is - registry disappears from any of serialisations after deref, although it contains all information about recursive fields, and i assume there is no other way of define recursive schemas. of course, i still could use underefed schema, but it much complicated

ikitommi 2021-05-20T18:55:05.034400Z

Can't recall where it was discussed, but we should clearly separate the locally registered schemas from normal registered ones and with the malli.util fns, expose the accumulated local registry, to be used in schema form. This makes the schemas visible and thus, serializable.

ikitommi 2021-05-20T18:55:26.034600Z

small change, clears thing a lot.

Vladislav 2021-05-20T19:04:15.034800Z

I tried to find some way of extract and then serialize registry from schema (`m/-registry`, and then malli.registry/schemas ), but sadly unsuccess - it still needs more class serialization (may be to deref every schema from it? - leave it for tomorrow)