3

I tried validating a map using the prismatic/schema library for clojure. here is my shape

(require '[schema.core :as s])
(def d {"a" s/Str "b" s/Int})

When I tried to validate it against a map, it throws the following exception

(s/validate d {"a" "@@#$" "b" 2})
RuntimeException More than one non-optional/required key schemata: ["a" "b"]  schema.core/find-extra-keys-schema (core.clj:705)

Am I do something wrong, or can't the schema library not validate against String keys ?

4

1 回答 1

4

You have to use

(def d {(s/required-key "a") s/Str (s/required-key "b") s/Int})

Only when using keywords as keys you can omit the required-key.

example=> (def d {(s/required-key "a") s/Str (s/required-key "b") s/Int})
#'schema-examples/d
example=> (s/validate d {"a" "@@#$" "b" 2})
{"a" "@@#$", "b" 2}
examples=>
于 2015-10-14T06:52:39.917 回答