-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
26 lines (22 loc) · 798 Bytes
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns swagger-schema-validator.core
(:require [clojure.java.io :as io]
[cheshire.core])
(:import [com.github.bjansen]
(java.io ByteArrayInputStream)
(com.github.bjansen.ssv SwaggerValidator)
(com.github.fge.jsonschema.core.report ProcessingReport)))
(defn- string->stream
[s]
(-> (.getBytes s "UTF-8")
(ByteArrayInputStream.)
io/reader))
(defn- ^ProcessingReport validate [schema definition json]
(-> (SwaggerValidator/forJsonSchema (string->stream schema))
(.validate json definition)))
(defn explain [schema definition json]
(-> (validate schema definition json)
.asJson
str
(cheshire.core/parse-string keyword)))
(defn valid? [schema definition json]
(.isSuccess (validate schema definition json)))