Getting Prismatic Schema to Compile Under 1.4
Monday, November 24th, 2014I've been trying to get some data validation code going, and one of the best looking libraries is Prismatic's Schema. It's got both clojure and clojurescript, as well as a very well thought out scheme. It's got capabilities to run tests on code, in-line, or as data to filter like tests. It's very nice.
Problem is, it's meant to use clojure 1.5.1 or better.
But I wanted to see if we could get it going in clojure 1.4.0 for the Storm topologies we have. Turns out, it wasn't all that easy. But it appears possible.
First, let's change a few things in the project.clj file. First, make the version something that's clear it's not the normal version:
(defproject prismatic/schema "0.3.4G"
and then, because clojure 1.4.0 doesn't have the EDN reader, we needed to add:
:dependencies [[potemkin "0.3.2"] [org.clojure/tools.reader "0.8.12"]]
and then changed the main version of clojure:
:profiles [{:dev {:dependencies [[org.clojure/clojure "1.4.0"]
And then in src/cljx/schema/coerce.cljx we need to reference the correct EDN reader:
#+clj [clojure.tools.reader.end :as end]
and then in test/cljx/schema/core_test.cljx we need to use a proper defprotocol for 1.4.0:
(defprotocol ATestProtocol (test-fn [x]))
And at this point, we can run:
$ lein do clean, reps, test
And it will work just fine - for the clojure part. The clojure script requires 1.5.1, but that's OK, as we don't need it.