zen-lang / zen

Library for model driven systems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

:zen/tags validation logic hardcoded into zen.store/validate-resource

KGOH opened this issue · comments

Zen symbol validation can not be reproduced with zen.validation or zen.v2-validation code:
:zen/tags are only validated on load here:

(mapv (fn [res] (validate-resource ctx res)))))))

zen/src/zen/store.clj

Lines 54 to 55 in 19e6508

(defn validate-resource [ctx res]
(let [tags (get res :zen/tags)

(let [{errs :errors} (v2/validate ctx schemas res)]

It looks like :zen/tags should be validated in zen.v2-validation/zen.validation and zen.store/validate-resource should just call validate function without handling :zen/tags explicitly

Steps to reproduce:

  • Prepare ztx:
    (def my-zrc
      {'myns '{ns myns
    
               tag {:zen/tags #{zen/schema}
                    :type zen/map
                    :require #{:foo}
                    :keys {:foo {:type zen/any}}}
    
               sym {:zen/tags #{tag}}}})
    
    (def ztx (zen.core/new-context {:memory-store my-zrc}))
    
    (zen.core/load-ns ztx (get my-zrc 'myns))
  • (zen.core/errors ztx) will show 2 errors
    [{:type "require",
      :message ":foo is required",
      :path [:foo],
      :schema [myns/tag :require],
      :resource myns/sym}
     {:message
      "Expected symbol 'myns/tag tagged with '#{zen/tag}, but only #{zen/schema}",
      :type "symbol",
      :path [:zen/tags 0],
      :schema [myns/tag :property :zen/tags :every 0 :tags],
      :resource myns/sym}]
  • But (zen.core/validate ztx #{'zen/schema} (zen.core/get-symbol ztx 'myns/sym)) will show only one error:
    {:errors
     [{:message
       "Expected symbol 'myns/tag tagged with '#{zen/tag}, but only #{zen/schema}",
       :type "symbol",
       :path [:zen/tags 0],
       :schema [zen/schema :property :zen/tags :every 0 :tags]}],
     :warnings [],
     :effects []}
    

Urgency: very low