malli

https://github.com/metosin/malli :malli:
rutledgepaulv 2020-09-05T02:43:15.098800Z

I was wondering if lsp integration was in the cards πŸ™‚ I would love to be able to write a malli schema and from it receive strong editor support for data that needs to conform to that schema (like some tools provide for xsd).

ikitommi 2020-09-05T07:48:57.115200Z

The demo on ClojureD was schematized malli fn's emitting clj-kondo type definitions. I'll make a real impl out of that now with the clj-together funding. Not the first thing, but will most likely need help with that @borkdude, will poke you when about to do that. The second thing, which would be a nice experiment is if malli itself could be used inside clj-kondo to validate both malli data and schemas, e.g.

(do-it {:Type "AWS::AppSync::ApiKey"
        :Descriptionz "kikka"})
.. would emit clj-kondo errors:
{:ApiId ["missing required key"]
 :Descriptionz ["should be spelled :Description"]}

ikitommi 2020-09-05T07:51:10.117300Z

autocomplete-stuff: I don't know how to do those, and most likely don't have to study that, but happy to help on Malli side if someone want's to try that out

ikitommi 2020-09-05T08:27:09.122Z

with the :multi dispatch key validation, it would yield:

(do-it {:Type "AWS::ApiGatway::UsagePlan"
        :Description "kikka"
        :UsagePlanName "kukka"}
.. would emit clj-kondo errors:
{:Type ["should be spelled \"AWS::ApiGateway::UsagePlan\""]}

borkdude 2020-09-05T08:29:18.123300Z

@ikitommi I tried a similar thing using the type system in clj-kondo. It can be done, but it only works at places where literal maps are passed. So when you use assoc et al, it already breaks (although I think I have some logic which tries to account for that, it's been a while)

borkdude 2020-09-05T08:29:57.123600Z

as an experiment, it'd be interesting what comes out of it

πŸ‘ 1
borkdude 2020-09-05T08:32:25.124500Z

I recently listened to a podcast with Tony Kay. He is working on something similar called GuardRails Pro which will be closed source

borkdude 2020-09-05T08:33:09.125200Z

It would be great to have a free alternative

ikitommi 2020-09-05T13:13:21.126Z

Looked up and listened the ClojureScript Podcast about GRP, sounds interesting.

ikitommi 2020-09-05T13:14:34.127100Z

Interesting times ahead, sounds like Clojure is getting mature :)

ikitommi 2020-09-05T13:33:03.130Z

@jeroenvandijk small changes: β€’ :dispatch is mandatory in :multi, e.g. can’t set via Schema creations opts => this makes it visible for error handling β€’ malli.error/with-spell-checking now understands :multi dispatch values if the :dispatch value is a keyword

ikitommi 2020-09-05T13:33:29.130400Z

(-> (m/explain
      Schema
      {:Type "AWS::AppSync::ApiKey"
       :Descriptionz "kikka"})
    (me/with-spell-checking)
    (me/humanize))
; loaded "AWS::AppSync::ApiKey"
; => {:ApiId ["missing required key"]
;     :Descriptionz ["should be spelled :Description"]}

(-> Schema
    (m/explain
      {:Type "AWS::ApiGatway::UsagePlan"
       :Description "kikka"
       :UsagePlanName "kukka"})
    (me/with-spell-checking)
    (me/humanize))
; => {:Type ["did you mean AWS::ApiGateway::UsagePlan"]}

ikitommi 2020-09-05T13:35:35.130800Z

full gist here: https://gist.github.com/ikitommi/06143540e6259323b95253e87e1ef710

2020-09-05T13:40:48.131100Z

Wow, super nice. Thanks!