Fork me on GitHub

I'm having trouble getting spec working with compojure-api. I have version "2.0.0-alpha28" of compojure-api installed. The validation is working fine with Schema, but when I change :coercion :spec to one endpoint for testing spec, the following error is thrown:

Caused by: java.lang.IllegalArgumentException: No implementation of method: :specify of protocol: #'compojure.api.coercion.spec/Specify found for class: nil
	at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:583)
	at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:575)
	at compojure.api.coercion.spec$eval19818$fn__19819$G__19809__19826.invoke(spec.clj:37)
	at compojure.api.coercion.spec$fn__19877.invokeStatic(spec.clj:78)
	at compojure.api.coercion.spec$fn__19877.invoke(spec.clj:78)
The code that is causing this error is:
(ns musician.instrument.api
  (:require [compojure.api.sweet :as api]
            [musician.instrument.db :as db]
            [ring.util.http-response :as res]
            [clojure.spec.alpha :as s]))

(s/def ::instruments (s/coll-of string?))

(api/defroutes routes
  (api/GET "/" {user-id :identity}
    :coercion :spec
    :summary "Get all user's instruments"
    :return ::instruments
    (res/ok (db/find-instruments-of-user {:user-id user-id}))))
What am I missing here?


Not sure if this is the problem you're facing but I've only seen the spec coercion applied to an entire context (like in


Is there documentation somewhere that says it's valid to apply to only a single route?