Skip to content

Commit

Permalink
Add min/max properties
Browse files Browse the repository at this point in the history
  • Loading branch information
hkupty committed Jan 6, 2021
1 parent fc5059b commit 18332a6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/malli/json_schema/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@
merge
(annotations->properties js-schema))))

(defn properties->malli [{:keys [required]} [k v]]
(defn properties->malli [required [k v]]
(cond-> [k]
(nil? (required k)) (conj {:optional true})
true (conj (schema->malli v))))

(defn- prop-size [pred?] (fn [-map] (pred? (count (keys -map)))))
(defn- min-properties [-min] (prop-size (partial <= -min)))
(defn- max-properties [-max] (prop-size (partial >= -max)))

(defn object->malli [v]
(let [required (into #{}
;; TODO Should use the same fn as $ref
Expand All @@ -74,7 +78,7 @@
(m/schema (cond-> [:map]
closed? (conj {:closed :true})
true (into
(map (partial properties->malli {:required required}))
(map (partial properties->malli required))
(:properties v))))))

(defmethod type->malli "string" [{:keys [pattern minLength maxLength enum]}]
Expand Down

0 comments on commit 18332a6

Please sign in to comment.