Skip to content

Commit

Permalink
0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Jan 15, 2015
1 parent 3253f5f commit fdf701d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
## 0.17.0 (15.1.2015)
- revert default spec location to `/api/docs` to be more backwards compatible. Swagger2-clients should use `swagger.json`.
- `ring.swagger.middleware/comp-mw` to make middleware parametrization easier:

```clojure
(def wrap-swagger2-ui
(comp-mw wrap-swagger-ui :swagger-docs "swagger.json"))
```

## 0.16.0 (14.1.2015)

- Swagger 2.0 support!!
- new namespace `ring.swagger.swagger2` with clean public API with Schemas
- **breaking change**: default spec location changed from `/api/docs` to `/swagger.json` (2.0 standard)
- **breaking change**: in `ring.swagger.middleware` the `catch-validation-error` is now `wrap-validation-error`
- takes an extra option: `:error-handler` to allow error response customization & `:catch-core-errors?` for
catching `:schema.core/error`s (defaults to `false`).
catching `:schema.core/error`s (defaults to `false`).
- one can now plug own coercers for `coerce` and `coerce!`
- use real swagger json schema validator for tests (`ring.swagger.validator`)
- potential **breaking changes** for library developers due massive refactoring
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metosin/ring-swagger "0.16.0"
(defproject metosin/ring-swagger "0.17.0"
:description "Swagger Spec for Ring Apps"
:url "https://github.com/metosin/ring-swagger"
:license {:name "Eclipse Public License"
Expand Down
6 changes: 5 additions & 1 deletion src/ring/swagger/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
[ring.util.http-response :refer [bad-request]])
(:import (schema.utils ValidationError)))

(defn comp-mw [mw & base-params]
(fn [handler & params]
(apply mw (concat [handler] base-params params))))

(defn stringify-error [error]
(postwalk
(fn [x]
Expand All @@ -26,7 +30,7 @@
into valid error respones. Accepts the following options:
:error-handler - a function of schema.utils.ErrorContainer -> response
:catch-core-errors? - consume also :schema.core/errors (default to false)"
:catch-core-errors? - consume also :schema.core/errors (defaults to false)"
[handler & {:keys [error-handler catch-core-errors?]
:or {error-handler default-error-handler
catch-core-errors? false}}]
Expand Down
2 changes: 1 addition & 1 deletion src/ring/swagger/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(second (re-find (re-pattern (str "^" root "[/]?(.*)")) uri)))

(defn conf-js [req {:keys [swagger-docs oauth2]
:or {swagger-docs "/swagger.json"
:or {swagger-docs "/api/docs" #_"/swagger.json"
oauth2 nil}}]
(let [swagger-docs (swagger/join-paths (swagger/context req) swagger-docs)
conf (cond-> {:url swagger-docs}
Expand Down
12 changes: 11 additions & 1 deletion test/ring/swagger/middleware_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(defn bad [_] (coerce! P {:b {:c nil}}))
(defn good [_] (coerce! P {:a 1, :b {:c :kikka}}))

(facts "catch-response"
(facts "wrap-validation-errors"

(fact "without middleware exception is thrown for validation error"
(good ..request..) =not=> (throws Exception)
Expand Down Expand Up @@ -42,3 +42,13 @@
(stringify-error (s/check P {:b {:bad 1}})) => {:a "missing-required-key"
:b {:bad "disallowed-key"
:c "missing-required-key"}})

(fact "comp-mw"
(let [mw1 (fn [_ & params] (fn [_] (apply hash-map params)))
mw2 (comp-mw mw1 :abba 2)
mw3 (comp-mw mw2 :abba 3 :jabba 3)]
((mw1 identity) ..request..) => {}
((mw1 identity :abba 1) ..request..) => {:abba 1}
((mw2 identity) ..request..) => {:abba 2}
((mw3 identity) ..request..) => {:abba 3 :jabba 3}
((mw3 identity :abba 4 :jabba 4 :doo 4) ..request..) => {:abba 4 :jabba 4 :doo 4}))
2 changes: 1 addition & 1 deletion test/ring/swagger/ui_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

(fact "with default parameters"
(conf-js nil {})
=> "window.API_CONF = {\"url\":\"/swagger.json\"};")
=> "window.API_CONF = {\"url\":\"/api/docs\"};")

(fact "with swagger-docs & oauth2 set"
(conf-js nil {:swagger-docs "/lost"
Expand Down

0 comments on commit fdf701d

Please sign in to comment.