Skip to content

Commit 8309988

Browse files
committed
Merge branch '1.1.x' of github.com:metosin/compojure-api into 1.1.x
2 parents af472c9 + 7e4f63b commit 8309988

File tree

7 files changed

+38
-26
lines changed

7 files changed

+38
-26
lines changed

src/compojure/api/coercion.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
[compojure.api.request :as request]
55
[compojure.api.coercion.core :as cc]
66
;; side effects
7-
compojure.api.coercion.register-schema
8-
compojure.api.coercion.register-spec)
7+
compojure.api.coercion.schema
8+
compojure.api.coercion.spec)
99
(:import (compojure.api.coercion.core CoercionError)))
1010

1111
(def default-coercion :schema)

src/compojure/api/coercion/register_schema.clj

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/compojure/api/coercion/register_spec.clj

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/compojure/api/coercion/schema.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
[compojure.api.coercion.core :as cc]
66
[clojure.walk :as walk]
77
[schema.core :as s]
8-
[compojure.api.common :as common]
9-
;; side effects
10-
compojure.api.coercion.register-schema)
8+
[compojure.api.common :as common])
119
(:import (java.io File)
1210
(schema.core OptionalKey RequiredKey)
1311
(schema.utils ValidationError NamedError)))
@@ -86,3 +84,5 @@
8684
(->SchemaCoercion :schema options))
8785

8886
(def default-coercion (create-coercion default-options))
87+
88+
(defmethod cc/named-coercion :schema [_] default-coercion)

src/compojure/api/coercion/spec.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
[clojure.walk :as walk]
77
[compojure.api.coercion.core :as cc]
88
[spec-tools.swagger.core :as swagger]
9-
[compojure.api.common :as common]
10-
;; side effects
11-
compojure.api.coercion.register-spec)
9+
[compojure.api.common :as common])
1210
(:import (clojure.lang IPersistentMap)
1311
(schema.core RequiredKey OptionalKey)
1412
(spec_tools.core Spec)
@@ -151,3 +149,5 @@
151149
(->SpecCoercion :spec options))
152150

153151
(def default-coercion (create-coercion default-options))
152+
153+
(defmethod cc/named-coercion :spec [_] default-coercion)

src/compojure/api/resource.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
(ns compojure.api.resource
22
(:require [compojure.api.routes :as routes]
33
[compojure.api.coerce :as coerce]
4+
[compojure.api.methods :as methods]
45
[ring.swagger.common :as rsc]
56
[schema.core :as s]
67
[plumbing.core :as p]
78
[compojure.api.middleware :as mw]))
89

910
(def ^:private +mappings+
10-
{:methods #{:get :head :patch :delete :options :post :put}
11+
{:methods methods/all-methods
1112
:parameters {:query-params [:query-params :query :string true]
1213
:body-params [:body-params :body :body false]
1314
:form-params [:form-params :formData :string true]

src/compojure/api/routes.clj

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
[linked.core :as linked]
1111
[compojure.response]
1212
[schema.core :as s])
13-
(:import [clojure.lang AFn IFn Var]))
13+
(:import (clojure.lang AFn IFn Var IDeref)
14+
(java.io Writer)))
1415

1516
;;
1617
;; Route records
@@ -47,6 +48,19 @@
4748
(update-in route [0] (fn [uri] (if (str/blank? uri) "/" uri))))
4849
(-get-routes handler options))))
4950

51+
(defn get-static-context-routes
52+
([handler]
53+
(get-static-context-routes handler nil))
54+
([handler options]
55+
(filter (fn [[_ _ info]] (get info :static-context?))
56+
(get-routes handler options))))
57+
58+
(defn- realize-childs [route]
59+
(update route :childs #(if (instance? IDeref %) @% %)))
60+
61+
(defn- filter-childs [route]
62+
(update route :childs (partial filter (partial satisfies? Routing))))
63+
5064
(defrecord Route [path method info childs handler]
5165
Routing
5266
(-get-routes [this options]
@@ -72,12 +86,25 @@
7286
IFn
7387
(invoke [_ request]
7488
(handler request))
89+
(invoke [_ request respond raise]
90+
(handler request respond raise))
91+
7592
(applyTo [this args]
7693
(AFn/applyToHelper this args)))
7794

7895
(defn create [path method info childs handler]
7996
(->Route path method info childs handler))
8097

98+
(defmethod print-method Route
99+
[this ^Writer w]
100+
(let [childs (some-> this realize-childs filter-childs :childs seq vec)]
101+
(.write w (str "#Route"
102+
(cond-> (dissoc this :handler :childs)
103+
(not (:path this)) (dissoc :path)
104+
(not (seq (:info this))) (dissoc :info)
105+
(not (:method this)) (dissoc :method)
106+
childs (assoc :childs childs))))))
107+
81108
;;
82109
;; Invalid route handlers
83110
;;

0 commit comments

Comments
 (0)