Fork me on GitHub
#malli
<
2023-03-04
>
pavlosmelissinos08:03:31

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?

pavlosmelissinos08:03:13

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

pavlosmelissinos08:03:15

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.

pavlosmelissinos10:03:48

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 duckie but I'd love to hear suggestions for improvements!

ikitommi18:03:03

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

šŸ™ 2
pavlosmelissinos21:03:25

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