This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-04
Channels
- # announcements (1)
- # babashka (41)
- # beginners (124)
- # cider (8)
- # clj-kondo (25)
- # cljs-dev (40)
- # clojars (4)
- # clojure (92)
- # clojure-europe (35)
- # clojure-italy (3)
- # clojure-nl (4)
- # clojure-uk (91)
- # clojuredesign-podcast (8)
- # clojurescript (41)
- # code-reviews (1)
- # cursive (11)
- # data-science (1)
- # datascript (76)
- # datomic (45)
- # emacs (4)
- # etaoin (3)
- # events (1)
- # figwheel-main (2)
- # fulcro (9)
- # graalvm (1)
- # jackdaw (6)
- # jobs (1)
- # jobs-discuss (3)
- # kaocha (4)
- # malli (25)
- # off-topic (42)
- # pathom (4)
- # reitit (11)
- # releases (2)
- # reveal (1)
- # shadow-cljs (53)
- # sql (4)
- # tools-deps (190)
- # vrac (19)
- # xtdb (6)
that look ok @jeroenvandijk?
@ikitommi it looks perfect! I need to wrap my head around it, but the demo looks exactly what I want. I’ll try to convert a spec project today and give some feedback
great! changes in the core are in this commit: https://github.com/metosin/malli/pull/252/commits/3a5c7f35141e32eea3b374b6a81e706377a44d26, need to add polish the code before merging in, most likely this week.
Does Malli have an equivalent of (clojure.spec.alpha/map-of string? string)
.e.g {"any-string-key" "any-string-value"}
?
As an alternative this seems to work:
(require '[malli.core :as m])
(defn map-of [k v]
(clojure.walk/postwalk-replace
{::k k
::v v}
'[:fn (fn [x] (and (map? x)
(every? (fn [[k v]]
(::k k)
(::v v))
x)))]))
(m/validate (map-of 'string? 'string?) {:a 1})
Thanks
Would it make sense to add validation on the schema definition? e.g. i did this in a nested schema
(m/validate '[:map string? string?] {})
I had no idea of course and I was looking for the place that was causing this message
java.lang.UnsupportedOperationException: count not supported on this type: Symbol
IntoSchema
protocol will have a methods that describe both children and properties as malli schemas. After that, malli validates the malli schemas :) That requires the regex-schemas, which is the next thing. So, yes, but not yet.
I was thinking of trying the non-lazy approach first, but I think the lazy version will be easier to debug 😅 I can print what faulty schema is being loaded just before it crashes
@ikitommi So far the lazyness works really nice. I’ll let you know when I’m done
Is it possible to somehow add the spellcheck on the dispatch as well? Would be super fancy 🙂 E.g. when I type
"AWS::AppSync::ApiK" ==> you misspelled "AWS::AppSync::ApiKey"
I’ve added a try/catch around the schema loading. Makes it much easier to debug a wrong definition:
(fn [type registry]
(let [definition (lookup-fn type)
schema (when definition
(try
(m/schema definition {:registry registry})
(catch Exception e
(throw (ex-info (str "Error while loading " type ": " (pr-str (ex-message e))) {:definition definition})))
))]
(println "loaded" (pr-str type))
schema))
should be possible. The spell checking reads the explain output. Just need to ensure :multi
emits error on invalid dispatch key that the spell checker understands. Internally, :map
and :multi
both use the entry-syntax, so might be just few loc.
As far as I can see the spelling feature is focussed on the misspelling of keys and not of values. I probably missing something though. I was missing this spelling on values also when I was spec with expound and spell-check. Maybe it’s a different kind of problem
ah wait i think i see some pointers
next step would be to make clj-kondo use malli somehow, so we would get static inspection.
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).
Sounds awesome!