This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-17
Channels
- # architecture (115)
- # asami (64)
- # aws (2)
- # babashka (65)
- # beginners (91)
- # calva (21)
- # clara (3)
- # cljdoc (5)
- # cljsrn (1)
- # clojure (331)
- # clojure-australia (15)
- # clojure-europe (16)
- # clojure-italy (7)
- # clojure-nl (8)
- # clojure-uk (10)
- # clojurescript (10)
- # conjure (4)
- # core-typed (6)
- # cryogen (12)
- # data-science (1)
- # datomic (9)
- # depstar (2)
- # emacs (1)
- # events (1)
- # figwheel-main (1)
- # fulcro (2)
- # graalvm (9)
- # helix (4)
- # java (45)
- # kaocha (4)
- # malli (14)
- # meander (4)
- # membrane (34)
- # mid-cities-meetup (6)
- # pedestal (3)
- # re-frame (7)
- # reitit (4)
- # shadow-cljs (4)
- # spacemacs (5)
- # sql (29)
- # tools-deps (22)
there are some gaps in the malli->clj-kondo integration, any insights welcome: https://github.com/metosin/malli/blob/cde74871ee5edc1525344f7a6e62d54fb1b00f5b/src/malli/clj_kondo.cljc. marked with ;;??
currently:
(require '[malli.clj-kondo :as mc])
(mc/transform
[:map
[:id string?]
[:tags {:optional true} [:set keyword?]]
[:address
[:map
[:street string?]
[:city string?]
[:zip {:optional true} int?]
[:lonlat [:tuple double? double?]]]]])
;{:op :keys
; :opt {:tags :set}
; :req {:id :string
; :address {:op :keys
; :opt {:zip :int}
; :req {:street :string
; :city :string
; :lonlat [:double :double]}}}}
btw, would be great if clj-kondo supported :min
and :max
for numbers & collections. nice demo about “more than types”, something like:
(ms/defn times :- :int
"times"
[x :- [:int {:min 3}]]
(* x x))
(times 2)
;; ^:--- clj-kondo error of "number should be at least 3"
Don't know if this a common enough problem in function calls. I haven't encountered this much I think. If there's a domain specific need to check this, one can also write a hook
ok. just wondering as clj-kondo already supports map-op-syntax, so if :int
could be defined as {:op :int}
, it would allow adding easily new keys that would be easy to check, e.g. malli could emit {:opt :int, :min 3}
from the example. Not sure how useful that would be, but:
• number min & max might be easy to implement on clj-kondo side?
• would be a great demo, as you can’t easily present these with simple typed langs liike Java
it has :pos-int
and :nat-int
which map to the clojure predicates. it basically only has that which exists as predicates in clojure 1.9+
@ikitommi Feel free to try out things with the clj-kondo type system. You can build a custom clj-kondo for your demo possibly
@ikitommi Ah, I can see why your approach might be problematic: https://github.com/borkdude/clj-kondo/blob/master/src/clj_kondo/impl/types.clj#L157-L163 So the literal value is mapped to a type tag. And then during checking that is resolved very cheaply, not executing any predicates, but just checking a keyword identity or a super simple graph, e.g. a pos-int is also an int
Hi guys, just getting my feet wet with malli. Quick question: when I try to transform a map to JSON-Schema, all the map's keywords are still Clojure keywords and thus invalid syntax in JSON-Schema. Sure, I could post-process it, but is this on purpose? What's the best way to get proper JSON-Schema?
@marcus.poparcus I think it would be better to emit strings directly. PR Welcome.