malli

https://github.com/metosin/malli :malli:
eraad 2020-10-30T00:05:53.360900Z

Hi! I’m using Malli schemas to generate a Swagger spec using Reitit (ie. “issue_date”). These schemas have encoding fns so “issue_date” is coerced to :document/issue-date so it can be saved into Datomic. I want to confirm if the Reitit coercers do validation after coercion right? Because I’m not getting it to validate as “issue_date” but :document/issue-date

eraad 2020-10-30T00:07:50.361900Z

It is what I can see from the code and from the behaviour. If I want to keep the json-like schemas for Swagger generation AND validate using those, I need to do coercion after all that manually right?

eraad 2020-10-30T00:08:18.362500Z

Or of course write my own Malli coercer that always decodes.

eraad 2020-10-30T00:12:01.362800Z

I would appreciate any pointers on this

ikitommi 2020-10-30T16:01:07.363700Z

@lmergen @rschmukler should there be m/assert?

2020-11-01T08:59:49.382800Z

i think there should be -- i have two functions myself actually, assert and have, where have is inspired by ptaoussanis' truss -- https://github.com/ptaoussanis/truss effectively, have does the assertion + also returns the input value if no failure was detected. this allows for a pattern such as

(let [foo (m/have foo-schema (get x :foo))]
  ...)
it's very effective. i would be happy to send a PR for the assert and/or have implementations i have right now (which seem to be doing the right thing)

ikitommi 2020-10-30T16:02:19.364500Z

@eraad coercion is decode + validate in reitit-malli

ikitommi 2020-10-30T16:03:22.365900Z

for responses, I recall it's validate + encode

ikitommi 2020-10-30T16:04:23.367500Z

have had a super busy two weeks, should have few full days of malli after next wed.

eraad 2020-10-30T16:21:38.368Z

Thanks @ikitommi got you

ikitommi 2020-10-30T16:30:40.376900Z

the m/defn, currently have a separate malli.schema ns, and few helper ns's under it. Will have the 1:1 Plumatic Schema m/defn for Malli. Once done, will do the real full malli->clj-kondo integration, that can be used with both malli-defn and aave, and a standard fdef -kinda way to annotate existing functions like in spec.

👍 1
borkdude 2020-10-30T16:31:03.377100Z

@ikitommi exciting!

👍 2
ikitommi 2020-10-30T16:32:47.379300Z

might be worth trying to write spec->malli conversion, so we could reuse all the existing fdefs out there. Also, zillion little things to do :)

rschmukler 2020-10-30T19:55:47.380800Z

@ikitommi once we have that I may take a crack at some nrepl middleware and cider integration. Right now you can spec generate and see spec definitions in documentation lookup in emacs. Only thing I miss from spec.

rschmukler 2020-10-30T19:56:23.381500Z

Re: m/assert - why not? I think it'll be attractive for some of those migrating from spec