metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
593 stars 94 forks source link

json-transformer not working correctly with set-specs #257

Open Wegi opened 3 years ago

Wegi commented 3 years ago

When using a set in a spec, the coercion with the json-transformer does not work correctly. Here is a minimal example:

(s/def ::hello #{:one :two :three})
(s/def ::test-set (s/keys :req-un [::hello]))

(st/coerce ::test-set
           (->>
             {:hello :one}
             (m/encode "application/json")
             (m/decode "application/json"))
           st/json-transformer)

;; => {:hello "one"}

Is it intended to provide the type hint manually as described in the custom coercion section (https://github.com/metosin/spec-tools/blob/master/docs/01_coercion.md)? If so, please close the issue again.

ikitommi commented 3 years ago

there is no auto-resolution of set types, you need to have (s/and keyword? #{::one :two :three}) for spec-tools to know the type