看起来如果 ::my-spec
验证成功,那么 (s/and ::my-spec ::my-spec)
也应该成功。
这是我的实际代码的简化版本,但我遇到了验证组合使用 s/and、s/keys 和 s/or 规范的一些数据的问题。这是我能够想到的最小化副本。
(s/def :a/coordinate
(s/or :double double?
:int int?))
(s/valid?
(s/keys)
{:a/coordinate 1.0})
;; true
(s/valid?
(s/and (s/keys))
{:a/coordinate 1.0})
;; true
(s/valid?
(s/and (s/keys)
(s/keys))
{:a/coordinate 1.0})
;; false
(s/explain-str
(s/and (s/keys)
(s/keys))
{:a/coordinate 1.0})
;; "[:double 1.0] - failed: double? in: [:a/coordinate] at: [:a/coordinate :double] spec: :a/coordinate\n[:double 1.0] - failed: int? in: [:a/coordinate] at: [:a/coordinate :int] spec: :a/coordinate\n"