This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-05
Channels
- # announcements (2)
- # babashka (23)
- # beginners (67)
- # biff (4)
- # calva (19)
- # cider (6)
- # clj-kondo (40)
- # clj-yaml (14)
- # clojure (3)
- # clojure-austin (13)
- # clojure-europe (18)
- # clojure-nl (1)
- # clojure-norway (26)
- # clojure-uk (5)
- # clojurescript (42)
- # datascript (2)
- # datomic (6)
- # emacs (32)
- # graalvm (8)
- # humbleui (12)
- # hyperfiddle (13)
- # jobs (5)
- # lambdaisland (1)
- # lsp (18)
- # malli (15)
- # off-topic (20)
- # overtone (1)
- # pathom (5)
- # pedestal (15)
- # portal (3)
- # reitit (13)
- # releases (1)
- # remote-jobs (1)
- # yamlscript (4)
so this is probably the wrong place to ask, but does anyone know of a malli-like lib that's implemented in native js? i've looked at options like zod , yup, joi. im not super impressed with any of them. i think ajv is probably the most data oriented, but it's tied tightly to the jsonschema spec. am i missing any relevent options i should consider before picking a dependency?
If I'm not mistaken, you can convert Malli schemas to JSONSchema, that could be the way to go I'm in the process of migrating my own solution where I have Prismatic Schema -> Avro -> Typescript types pipeline, and instead go with Malli -> JSONSchema to keep things simpler, but it's very early days
i'm in the sad position of not being able to use any clojure / clojurescript (yet)... but i can't imagine building anything resilient without the help of prismatic/spec or malli
I think Zod combined with TS is what most people use, I have a somewhat narrow view into the JS world but that's I've seen in the wild
but yes, "types at the edges" are a necessity in Clojure, just to maintain one's sanity ;-)
I remember trying out yup-ast
at one point - https://github.com/WASD-Team/yup-ast
I want a map schema with required key :a
and for both or neither :b
and :c
to be present. Is that possible?
Maybe:
[:or
[:map [:a int?] [:b int?] [:c int?]]
[:map [:a int?]]]
It doesn't seem to translate properly to JSON Schema, mind you
Unfortunately no.
(malli.error/humanize
(malli.core/explain
[:or
[:map [:a int?] [:b int?] [:c int?]]
[:map [:a int?]]]
{:a 1
:c 1}))
=> nil
This works if I’m willing to close the more minimal schema
[:or [:map [:a int?] [:b int?] [:c int?]] [:map {:closed true} [:a int?]]]
Interestingly, that generates not the expected JSON Schema, but it does generate a correct Swagger schema 🙂 https://malli.io/?value=%7B%3Aa%201%7D&schema=%5B%3Aor%20%5B%3Amap%20%5B%3Aa%20int%3F%5D%20%5B%3Ab%20int%3F%5D%20%5B%3Ac%20int%3F%5D%5D%20%5B%3Amap%20%7B%3Aclosed%20true%7D%20%5B%3Aa%20int%3F%5D%5D%5D
What’s wrong with its JSON Schema?