Fork me on GitHub
#malli
<
2021-05-27
>
Ben Sless18:05:10

I'm looking at JSON Schema now and trying to write it out with malli and recursive schemas (with the intention of writing a transformer from it to malli) I'm using this BNF as reference https://cswr.github.io/JsonSchema/spec/grammar/ I'm wondering what's the best schema to pick for modelling it A lot of it is defined in terms of key-value pairs I thought I'd try modelling it as a union for convenience I defined

(defn -ref-u [& args] (into [:union] (map (fn [k] [:ref k])) args))
Then
;; JSDoc := { ( id, )? ( defs, )? JSch }
   ;; id := "id": "uri"
   ;; defs := "definitions": { kSch (, kSch)*}
   ;; kSch := kword: { JSch }
Becomes
::JSDoc (-ref-u ::id ::defs ::JSch)
   ::id [:map [:id {:optional true} [:ref ::uri]]]
   ::defs [:map [:definitions {:optional true} [:map-of :keyword [:ref ::JSch]]]]
But when it comes to n>=1 map schemas which are one-of types, I'm stumped
;; JSch := ( res (, res)*)
i.e., the map should have at least one res where it's defined as
;; res := type | strRes | numRes | arrRes | objRes | multRes | refSch | title | description
   ::res (-ref-u ::type ::strRes ::numRes ::arrRes ::objRes ::multRes ::refSch ::title ::description)
Ideally, I'd want some schema between map-of and map I'm also not 100% clear on the difference between union and merge and if they're even the right choice. Should I perhaps customize a -collection-schema?

ikitommi04:05:25

have looked at it, but haven’t heard of anyone using. not super popular.

ikitommi04:05:50

but, I nice idea. not sure how many ways there are to describe such things.