diff --git a/CHANGELOG.md b/CHANGELOG.md index e93d4be7..4e275e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ See also: [compojure-api 1.1.x changelog](./CHANGELOG-1.1.x.md) +## Next +* Lazily load spec and schema coercion support to preserve Clojure 1.8 support for 1.1.x + ## 2.0.0-alpha34-SNAPSHOT * **BREAKING CHANGE**: `:formatter :muuntaja` sometimes required for `api{-middleware}` options * to prepare for 1.x compatibility, :muuntaja must be explicitly configured diff --git a/src/compojure/api/coercion.clj b/src/compojure/api/coercion.clj index a83a7082..0dd26b04 100644 --- a/src/compojure/api/coercion.clj +++ b/src/compojure/api/coercion.clj @@ -3,8 +3,9 @@ [compojure.api.exception :as ex] [compojure.api.request :as request] [compojure.api.coercion.core :as cc] - [compojure.api.coercion.schema] - [compojure.api.coercion.spec]) + ;; side effects + compojure.api.coercion.register-schema + compojure.api.coercion.register-spec) (:import (compojure.api.coercion.core CoercionError))) (def default-coercion :schema) diff --git a/src/compojure/api/coercion/register_schema.clj b/src/compojure/api/coercion/register_schema.clj new file mode 100644 index 00000000..e1e8f993 --- /dev/null +++ b/src/compojure/api/coercion/register_schema.clj @@ -0,0 +1,8 @@ +(ns compojure.api.coercion.register-schema + (:require [compojure.api.coercion.core :as cc])) + +(defmethod cc/named-coercion :schema [_] + (deref + (or (resolve 'compojure.api.coercion.schema/default-coercion) + (do (require 'compojure.api.coercion.schema) + (resolve 'compojure.api.coercion.schema/default-coercion))))) diff --git a/src/compojure/api/coercion/register_spec.clj b/src/compojure/api/coercion/register_spec.clj new file mode 100644 index 00000000..143320fb --- /dev/null +++ b/src/compojure/api/coercion/register_spec.clj @@ -0,0 +1,8 @@ +(ns compojure.api.coercion.register-spec + (:require [compojure.api.coercion.core :as cc])) + +(defmethod cc/named-coercion :spec [_] + (deref + (or (resolve 'compojure.api.coercion.spec/default-coercion) + (do (require 'compojure.api.coercion.spec) + (resolve 'compojure.api.coercion.spec/default-coercion))))) diff --git a/src/compojure/api/coercion/schema.clj b/src/compojure/api/coercion/schema.clj index b308d0c2..b310fc18 100644 --- a/src/compojure/api/coercion/schema.clj +++ b/src/compojure/api/coercion/schema.clj @@ -84,5 +84,3 @@ (->SchemaCoercion :schema options)) (def default-coercion (create-coercion default-options)) - -(defmethod cc/named-coercion :schema [_] default-coercion) diff --git a/src/compojure/api/coercion/spec.clj b/src/compojure/api/coercion/spec.clj index 9b20481a..ea8cf4b6 100644 --- a/src/compojure/api/coercion/spec.clj +++ b/src/compojure/api/coercion/spec.clj @@ -149,5 +149,3 @@ (->SpecCoercion :spec options)) (def default-coercion (create-coercion default-options)) - -(defmethod cc/named-coercion :spec [_] default-coercion)