Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KGOH opened this issue Sep 12, 2022 · 0 comments
Open

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

KGOH opened this issue Sep 12, 2022 · 0 comments
Labels
future issues that are documented for the future use

Comments

@KGOH
Copy link
Contributor

KGOH commented Sep 12, 2022

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

@carbon-hvze carbon-hvze added the future issues that are documented for the future use label Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future issues that are documented for the future use
Projects
None yet
Development

No branches or pull requests

2 participants