Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn- minimum-required-dimensions
- "Find a list of minimum required dimensions for the schema.
- e.g. An array of array of strings might be '(2 0 3), meaning the string must
- have length three, there can be zero or more strings in an array, and there
- must be three or more arrays of strings in the array of arrays of strings.
- To simplify logic, we keep a dimension for the innermost type, even if it is
- an atomic type and doesn't make sense."
- [schema]
- (reduce
- (fn [as bs]
- (let [length (max (count as) (count bs))
- as (concat as (repeat (- length (count as)) 0))
- bs (concat bs (repeat (- length (count bs)) 0))]
- (map max as bs)))
- (list)
- (m/search schema
- {"minLength" (m/some ?n)} (list ?n)
- {"type" "array"} (list 0 0)
- {"items" (m/some (m/cata ?dims))} (cons 0 ?dims)
- {"allOf" (m/scan (m/cata ?dims))} ?dims
- _ (list 0))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement