|
27 | 27 | (s/def ::keys-no-req (s/keys :opt [::e]
|
28 | 28 | :opt-un [::e]))
|
29 | 29 |
|
| 30 | +(defmulti event-payload :action) |
| 31 | + |
| 32 | +(s/def :event.payload.add/action #{:add}) |
| 33 | +(s/def :event.payload.add/payload int?) |
| 34 | + |
| 35 | +(defmethod event-payload :add |
| 36 | + [_] |
| 37 | + (s/keys :req-un [:event.payload.add/action :event.payload.add/payload])) |
| 38 | + |
| 39 | +(s/def :event.payload.result/action #{:result}) |
| 40 | +(s/def :event.payload.result/payload nil?) |
| 41 | + |
| 42 | +(defmethod event-payload :result |
| 43 | + [_] |
| 44 | + (s/keys :req-un [:event.payload.result/action] |
| 45 | + :opt-un [:event.payload.result/payload])) |
| 46 | + |
30 | 47 | (deftest simple-spec-test
|
31 | 48 | (testing "primitive predicates"
|
32 | 49 | ;; You're intented to call jsc/to-json with a registered spec, but to avoid
|
|
99 | 116 | :properties {"spec-tools.json-schema-test/integer" {:type "integer"}
|
100 | 117 | "spec-tools.json-schema-test/string" {:type "string"}}
|
101 | 118 | :required ["spec-tools.json-schema-test/integer" "spec-tools.json-schema-test/string"]}))
|
| 119 | + (is (= (jsc/transform (s/multi-spec event-payload :action)) |
| 120 | + {:anyOf [{:type "object" :properties {"action" {:enum [:result]} "payload" {:type "null"}} :required ["action"]} |
| 121 | + {:type "object" |
| 122 | + :properties {"action" {:enum [:add]} "payload" {:type "integer" :format "int64"}} |
| 123 | + :required ["action" "payload"]}]})) |
102 | 124 | (is (= (jsc/transform (s/every integer?)) {:type "array" :items {:type "integer"}}))
|
103 | 125 | (is (= (jsc/transform (s/every-kv string? integer?))
|
104 | 126 | {:type "object" :additionalProperties {:type "integer"}}))
|
|
0 commit comments