Fork me on GitHub
#malli
<
2020-10-30
>
eraad00:10:53

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

eraad00:10:50

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?

eraad00:10:18

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

eraad00:10:01

I would appreciate any pointers on this

ikitommi16:10:07

@lmergen @rschmukler should there be m/assert?

lmergen08:11:49

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)

ikitommi16:10:19

@eraad coercion is decode + validate in reitit-malli

ikitommi16:10:22

for responses, I recall it's validate + encode

ikitommi16:10:23

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

eraad16:10:38

Thanks @ikitommi got you

ikitommi16:10:40

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.

👍 3
ikitommi16:10:47

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

rschmukler19:10:47

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

rschmukler19:10:23

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