似乎如果 ::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"