Skip to content

Commit 75fe5bd

Browse files
committed
Merge pull request #215 from metosin/mw-execution-order
Small fixes for 1.0.0-RC1
2 parents 7ab4d21 + c0683a3 commit 75fe5bd

13 files changed

Lines changed: 172 additions & 159 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.0.0-SNAPSHOT
1+
## 1.0.0-RC1 (1.2.2016)
22

33
* Move from compile-time to runtime route resolution.
44
* Most of the internal macro magic has been vaporized
@@ -53,6 +53,7 @@ Previously required a `type => matcher` map. Options are checked against `type =
5353
descriptive error is thrown when api is created with the old options format.
5454

5555
* **BREAKING**: Renamed `middlewares` to `middleware` and `:middlewares` key (restructuring) to `:middleware`
56+
* will break at macro-expansion time with helpful exception
5657

5758
* **BREAKING**: Middleware must be defined as data: both middleware macro and :middleware restructuring
5859
take a vector of middleware containing either
@@ -67,6 +68,9 @@ take a vector of middleware containing either
6768

6869
* **BREAKING**: (Custom restructuring handlers only) `:parameters` key used by `restructure-param`
6970
has been renamed to `:swagger`.
71+
* will break at macro-expansion time with helpful exception
72+
73+
* **BREAKING**: `compojure.api.legacy` namespace has been removed.
7074

7175
### Migration guide
7276

@@ -82,6 +86,10 @@ https://github.com/metosin/compojure-api/wiki/Migration-Guide-to-1.0.0
8286

8387
* `swagger-docs` and `swagger-ui` are now functions instead of macros.
8488

89+
* Coercer cache is now at api-level with 10000 entries.
90+
91+
* Code generated from restructured route macros is much cleaner now
92+
8593
* Coercion is on by default for standalone (apiless) endpoints.
8694

8795
```clj

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Stuff on top of [Compojure](https://github.com/weavejester/compojure) for making
3232
[ring.util.http-response :refer :all]))
3333

3434
(defapi app
35-
(GET* "/hello" []
35+
(GET "/hello" []
3636
:query-params [name :- String]
3737
(ok {:message (str "Hello, " name)})))
3838
```
@@ -57,12 +57,12 @@ Stuff on top of [Compojure](https://github.com/weavejester/compojure) for making
5757
{:info {:title "My Swagger API"
5858
:description "Compojure Api example"}
5959
:tags [{:name "api", :description "sample api"}]})
60-
(context* "/api" []
60+
(context "/api" []
6161
:tags ["api"]
62-
(GET* "/hello" []
62+
(GET "/hello" []
6363
:query-params [name :- String]
6464
(ok {:message (str "Hello, " name)}))
65-
(POST* "/pizza" []
65+
(POST "/pizza" []
6666
:return Pizza
6767
:body [pizza Pizza]
6868
:summary "echoes a pizza"

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject metosin/compojure-api "1.0.0-SNAPSHOT"
1+
(defproject metosin/compojure-api "1.0.0-RC1"
22
:description "Compojure Api"
33
:url "https://github.com/metosin/compojure-api"
44
:license {:name "Eclipse Public License"
@@ -22,6 +22,7 @@
2222
:source-paths ["examples/src"]
2323
:dependencies [[org.clojure/clojure "1.7.0"]
2424
[http-kit "2.1.19"]
25+
[reloaded.repl "0.2.1"]
2526
[com.stuartsierra/component "0.3.1"]]}
2627
:dev {:repl-options {:init-ns user}
2728
:plugins [[lein-clojars "0.9.1"]

src/compojure/api/api.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
[compojure.api.middleware :as middleware]
55
[compojure.api.routes :as routes]
66
[compojure.api.common :as common]
7-
[clojure.tools.macro :as macro]
8-
[ring.swagger.common :as rsc]))
7+
[ring.swagger.common :as rsc]
8+
[compojure.api.meta :as meta]))
99

1010
(def api-defaults
1111
(merge
@@ -46,6 +46,7 @@
4646
api-handler (-> handler
4747
(middleware/api-middleware (dissoc options :api))
4848
(middleware/wrap-options {:paths paths
49+
:coercer (meta/memoized-coercer)
4950
:lookup lookup}))]
5051
(routes/create nil nil {} [handler] api-handler)))
5152

src/compojure/api/core.clj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
[bindings & body]
3131
`(let ~bindings (routes ~@body)))
3232

33-
(defn undocumented [& handlers]
33+
(defn undocumented
34+
"Routes without route-documentation. Can be used to wrap routes,
35+
not satisfying compojure.api.routes/Routing -protocol."
36+
[& handlers]
3437
(let [handlers (keep identity handlers)]
3538
(routes/create nil nil {} nil (ring-handler handlers))))
3639

@@ -41,12 +44,11 @@
4144
do not match the request uri. Be careful with middlewares that
4245
have side-effects."
4346
[middleware & body]
44-
(let [routes? (> (count body) 1)]
45-
`(let [body# ~(if routes? `(routes ~@body) (first body))
46-
wrap-mw# (mw/compose-middleware ~middleware)]
47-
(routes/create "" nil {} [body#] (wrap-mw# body#)))))
47+
`(let [body# (routes ~@body)
48+
wrap-mw# (mw/compose-middleware ~middleware)]
49+
(routes/create nil nil {} [body#] (wrap-mw# body#))))
4850

49-
(defmacro context [& args] (meta/restructure nil args {:routes #'routes}))
51+
(defmacro context [& args] (meta/restructure nil args {:context? true}))
5052

5153
(defmacro GET [& args] (meta/restructure :get args nil))
5254
(defmacro ANY [& args] (meta/restructure nil args nil))

src/compojure/api/exception.clj

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns compojure.api.exception
2-
(:require [ring.util.http-response :refer [internal-server-error bad-request]]
3-
[clojure.walk :refer [postwalk]]
2+
(:require [ring.util.http-response :as response]
3+
[clojure.walk :as walk]
44
[compojure.api.impl.logging :as logging]
55
[schema.utils :as su])
66
(:import [schema.utils ValidationError NamedError]
@@ -18,44 +18,44 @@
1818
expose secret details."
1919
[^Exception e data req]
2020
(logging/log! :error e (.getMessage e))
21-
(internal-server-error {:type "unknown-exception"
22-
:class (.getName (.getClass e))}))
21+
(response/internal-server-error {:type "unknown-exception"
22+
:class (.getName (.getClass e))}))
2323

2424
(defn stringify-error
2525
"Stringifies symbols and validation errors in Schema error, keeping the structure intact."
2626
[error]
27-
(postwalk
28-
(fn [x]
29-
(cond
30-
(instance? ValidationError x) (str (su/validation-error-explain x))
31-
(instance? NamedError x) (str (su/named-error-explain x))
32-
:else x))
33-
error))
27+
(walk/postwalk
28+
(fn [x]
29+
(cond
30+
(instance? ValidationError x) (str (su/validation-error-explain x))
31+
(instance? NamedError x) (str (su/named-error-explain x))
32+
:else x))
33+
error))
3434

3535
(defn response-validation-handler
3636
"Creates error response based on Schema error."
3737
[e data req]
38-
(internal-server-error {:errors (stringify-error (su/error-val data))}))
38+
(response/internal-server-error {:errors (stringify-error (su/error-val data))}))
3939

4040
(defn request-validation-handler
4141
"Creates error response based on Schema error."
4242
[e data req]
43-
(bad-request {:errors (stringify-error (su/error-val data))}))
43+
(response/bad-request {:errors (stringify-error (su/error-val data))}))
4444

4545
(defn schema-error-handler
4646
"Creates error response based on Schema error."
4747
[e data req]
4848
; FIXME: Why error is not wrapped to ErrorContainer here?
49-
(bad-request {:errors (stringify-error (:error data))}))
49+
(response/bad-request {:errors (stringify-error (:error data))}))
5050

5151
(defn request-parsing-handler
5252
[^Exception ex data req]
5353
(let [cause (.getCause ex)]
54-
(bad-request {:type (cond
55-
(instance? JsonParseException cause) "json-parse-exception"
56-
(instance? ParserException cause) "yaml-parse-exception"
57-
:else "parse-exception")
58-
:message (.getMessage cause)})))
54+
(response/bad-request {:type (cond
55+
(instance? JsonParseException cause) "json-parse-exception"
56+
(instance? ParserException cause) "yaml-parse-exception"
57+
:else "parse-exception")
58+
:message (.getMessage cause)})))
5959

6060
;;
6161
;; Logging

src/compojure/api/legacy.clj

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

0 commit comments

Comments
 (0)