You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently contains a usable JSON schema validator using cheshire to parse JSON.
Supportes linked schemas with $ref and allows user to specify
how linked URIs are loaded.
The macro version has problems with recursive and huge schemas.
A schema that later links to itself with a "#" pointer causes an ever expanding
macro expansion to take place and fails. That case requires a rethink of the
macro version. The macro may also fail when the generated function would exceed
the JVM limit on allowed code in a single method (64k).
Currently there are 47 tests with 658 assertions.
See suite_test.clj for
a the list of tests in the JSON schema test suite that are skipped.
Usage
The function version (runtime loading of schema):
(nsmy.app
(:require [webjure.json-schema.validator :refer [validate]]
[cheshire.core :as cheshire]))
;;; then in some function
(validate (cheshire/parse-string json-schema)
(cheshire/parse-string json-data))
Macro version loads and parses the schema and generates the validation function at compile time.
The returned errors are exactly the same as in the runtime version.
(nsmy.app
(:require [webjure.json-schema.validator.macro :refer [make-validator]]
[cheshire.core :as cheshire]))
(defmy-schema-validator
(make-validator (cheshire/parse-string json-schema) {}))
;; Then in some function
(my-schema-validator (cheshire/parse-string json-data))