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

:ref fing unqualified keyword throws :invalid-ref #1107

Open
andrewzhurov opened this issue Sep 22, 2024 · 3 comments
Open

:ref fing unqualified keyword throws :invalid-ref #1107

andrewzhurov opened this issue Sep 22, 2024 · 3 comments

Comments

@andrewzhurov
Copy link

andrewzhurov commented Sep 22, 2024

(m/validate [:schema {:registry {:init-evt [:map {:closed true}]
                                 :deep-evt [:map {:closed true} [:prev-evt [:ref :evt]]]
                                 :evt      [:multi {:dispatch (comp some? :prev-evt)}
                                            [true :deep-evt]
                                            [false :init-evt]]}}
             :evt]
            {})
;; => #error {:message ":malli.core/invalid-ref", :data {:type :malli.core/invalid-ref, :message :malli.core/invalid-ref, :data {:ref :evt}}}
(m/validate [:schema {:registry {::init-evt [:map {:closed true}]
                                 ::deep-evt [:map {:closed true} [:prev-evt [:ref ::evt]]]
                                 ::evt      [:multi {:dispatch (comp some? :prev-evt)}
                                             [true ::deep-evt]
                                             [false ::init-evt]]}}
             ::evt]
            {})
;; => true

I guess throwing wasn't intended, as :ref can be used with strings (so not required to have refs qualified)

@opqdonut
Copy link
Member

Currently malli only allows strings, vars and qualified symbols/keywords. This is probably to avoid conflicting with the built-ins.

(defn -reference? [?schema] (or (string? ?schema) (qualified-ident? ?schema) (var? ?schema)))

@andrewzhurov
Copy link
Author

andrewzhurov commented Sep 26, 2024

@opqdonut thanks for the link.

This is probably to avoid conflicting with the built-ins.

Hm, presently one may set a custom schema under a :keyword that some built-in schema usually uses.
Is there some custom handling of schema based on the name a schema's given?
I'd assume it does not matter how you name things, the content that the name refers to contributes to semantics.

If not, perhaps would be best to shown a warn/error at the step where you try to register.
"The name you want to use for this schema has special meaning in malli and would hamper its work, try another one"
And allow :keyword names that are not colliding.

@opqdonut
Copy link
Member

Yeah the docs and the error messages could be better here, agreed. I don't know why bare keywords are not allowed for refs. @ikitommi is probably the only one who knows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants