spec-tools icon indicating copy to clipboard operation
spec-tools copied to clipboard

s/explain-data throws exception for s/map-of spec with a s/or key

Open rfhayashi opened this issue 2 years ago • 1 comments

(s/explain-data
 (st/spec
  (s/map-of (s/or :keyword keyword? :string string?) any?))
 {:a 1})

throws a nth not supported on this type: Keyword exception.

This is due to a known issue of clojure spec (https://clojure.atlassian.net/browse/CLJ-2199).

Although we could wait for that fix, I think the call to s/unform here seems unnecessary since at that point we still have the original value. Doing this did solve the problem for me.

Is my understanding correct? Wanted to confirm before opening a PR.

rfhayashi avatar Oct 28 '21 16:10 rfhayashi

Wanted to conf_o_rm (ah!) that the fix above from @rfhayashi works here as well against the following spec:

(s/def ::age nat-int?)

(def age-interval-bound
  (ds/or {:infinity (s/spec #{##Inf ##-Inf})
          :nat-int ::age}))
(def age-interval-bound-spec (ds/spec {:name ::age-interval-bound :spec age-interval-bound}))
(s/def ::age-interval-bound age-interval-bound-spec)

(def age-interval
  {:lower-bound age-interval-bound
   :upper-bound age-interval-bound
   (ds/opt :open-lower) boolean?
   (ds/opt :open-upper) boolean?})
(def age-interval-spec (ds/spec {:name ::age-interval :spec age-interval}))
(s/def ::age-interval age-interval-spec)

Looking forward to a patch (that I can definitely open if the fix is acceptable). Thanks!

arichiardi avatar Mar 19 '24 16:03 arichiardi