diff --git a/src/zen/schema.clj b/src/zen/schema.clj index bb93586..2376876 100644 --- a/src/zen/schema.clj +++ b/src/zen/schema.clj @@ -154,6 +154,7 @@ (defmethod compile-key :require [_ _ _] {:when map?}) (defmethod compile-key :values [_ _ _] {:when map?}) (defmethod compile-key :schema-key [_ _ _] {:when map?}) +(defmethod compile-key :keyname-schemas [_ _ _] {:when map?}) (defmethod compile-key :scale [_ _ _] {:when number?}) (defmethod compile-key :precision [_ _ _] {:when number?}) @@ -347,3 +348,21 @@ vtx*)) vtx schemas))))) + + +(register-compile-key-interpreter! + [:keyname-schemas ::navigate] + (fn [_ ztx {:keys [tags]}] + (fn [vtx data opts] + (let [rule-fn + (fn [vtx* [schema-key data*]] + (if-let [sch (and (qualified-ident? schema-key) (utils/get-symbol ztx (symbol schema-key)))] + ;; TODO add test on nil case + (if (or (nil? tags) + (clojure.set/subset? tags (:zen/tags sch))) + (-> (validation.utils/node-vtx&log vtx* [:keyname-schemas schema-key] [schema-key]) + ((get-cached ztx sch false) data* opts) + (validation.utils/merge-vtx vtx*)) + vtx*) + vtx*))] + (reduce rule-fn vtx data))))) diff --git a/src/zen/v2_validation.clj b/src/zen/v2_validation.clj index 3a76c8a..aeebfea 100644 --- a/src/zen/v2_validation.clj +++ b/src/zen/v2_validation.clj @@ -450,24 +450,6 @@ Probably safe to remove if no one relies on them" vtx ks))))) -(defmethod compile-key :keyname-schemas - [_ ztx {:keys [tags]}] - {:when map? - :rule - (fn [vtx data opts] - (let [rule-fn - (fn [vtx* [schema-key data*]] - (if-let [sch (and (qualified-ident? schema-key) (utils/get-symbol ztx (symbol schema-key)))] - ;; TODO add test on nil case - (if (or (nil? tags) - (clojure.set/subset? tags (:zen/tags sch))) - (-> (node-vtx&log vtx* [:keyname-schemas schema-key] [schema-key]) - ((get-cached ztx sch false) data* opts) - (merge-vtx vtx*)) - vtx*) - vtx*))] - (reduce rule-fn vtx data)))}) - (defmethod compile-key :default [schema-key ztx sch-params] (cond (qualified-ident? schema-key)