This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-04
Channels
- # announcements (123)
- # asami (1)
- # babashka (50)
- # beginners (49)
- # biff (21)
- # calva (48)
- # cider (6)
- # clj-yaml (8)
- # cljsrn (2)
- # clojure (9)
- # clojure-conj (1)
- # clojure-indonesia (1)
- # clojure-losangeles (1)
- # clojure-uk (18)
- # clojurescript (21)
- # data-science (19)
- # datahike (13)
- # events (1)
- # fulcro (1)
- # honeysql (4)
- # hyperfiddle (40)
- # improve-getting-started (3)
- # inf-clojure (1)
- # malli (6)
- # off-topic (45)
- # releases (3)
- # rewrite-clj (14)
- # scittle (1)
- # shadow-cljs (57)
- # tools-deps (1)
- # vim (13)
- # xtdb (14)
I've picked up from where https://github.com/metosin/malli/pull/211 left off because I'd love to have json-schema import for a project,
However, when trying to invert the tests in malli.json-schema-test
, some of the tests fail because https://github.com/metosin/malli/pull/211/commits/fc5059b0886c20eb2497f3244b9a79eeec71d9d2malli converter recursively uses >`malli.util/update-properties` that apparently converts all the symbols to schema instances. Does anyone know why adding annotations is necessary at that point and if it's ok to do a single pass at the end instead?
an example to illustrate the issue:
(schema->malli {:type "string"})
;;=> string?
(= string? (schema->malli {:type "string"}))
;;=> false
(type (schema->malli {:type "string"}))
;;=> :malli.core/schema
(type string?)
;;=> clojure.core$string_QMARK___5475
Oh, I see, I can't call it at the end because it has to get the annotations of each json-schema property. Still, any suggestions for how to solve this? I suppose I could duplicate the expected pairs and modify the copy but it would be neat if I could reuse the existing one.
I've solved the false negatives by replacing
(is (= schema (sut/schema->malli json-schema)))
with
(is (mu/equals (m/schema schema) (sut/schema->malli json-schema)))
but now the diff isn't as nice š
I'm no longer blocked but I'd love to hear suggestions for improvements!
Yes, you should check the forms, not instances. Some suggestion:
ā¢ would generate :string
instead, I guess it contributes to better errors too
ā¢ You can just say (is (= :string (m/form (sut/...))))
to get proper diffs
> would generate :string instead, I guess it contributes to better errors too
>
Great feedback, thanks! I'm kinda new to malli so I'm still cargo-culting my way, sorry, š
> You can just say (is (= :string (m/form (sut/...)))) to get proper diffs
>
This works for strings but there isn't a :pos-int
, right? So I'm "stuck" with pos-int?
which has the same issue. Or do you mean it should generate something like [:int {:min 1}]
or [:and :int [:> 0]]
instead? Not sure what the idioms are.