Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename old reitit.ring.spec and move multipart specs to new ns #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md

## Unreleased

### `reitit-ring`

- **BREAKING:** `reitit.ring.spec` namespace has been renamed to `reitit.ring.validate.spec`

### `reitit-spec`

- **BREAKING:** Added `reitit.ring.spec` namespace with specs for multipart parameter coercion.
**This replaces old `reitit.ring.spec` namespace with different namespace.**

### `reitit-middleware`

- **BREAKING:** `temp-file-part`, `bytes-part` and related specs have been removed from
`reitit.ring.middleware.multipart` namespace and been moved to `reitit.ring.spec`
namespace.

## 0.4.2 (2020-01-17)

### `reitit`
Expand Down
4 changes: 2 additions & 2 deletions doc/ring/route_data_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Ring route validation works [just like with core router](../basics/route_data_validation.md), with few differences:

* `reitit.ring.spec/validate` should be used instead of `reitit.spec/validate` - to support validating all endpoints (`:get`, `:post` etc.)
* `reitit.ring.validate.spec/validate` should be used instead of `reitit.spec/validate` - to support validating all endpoints (`:get`, `:post` etc.)
* With `clojure.spec` validation, Middleware can contribute to route spec via `:specs` key. The effective route data spec is router spec merged with middleware specs.

## Example
Expand All @@ -12,7 +12,7 @@ A simple app with spec-validation turned on:
```clj
(require '[clojure.spec.alpha :as s])
(require '[reitit.ring :as ring])
(require '[reitit.ring.spec :as rrs])
(require '[reitit.ring.validate.spec :as rrs])
(require '[reitit.spec :as rs])
(require '[expound.alpha :as e])

Expand Down
6 changes: 3 additions & 3 deletions examples/ring-malli-swagger/src/example/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
[reitit.ring.middleware.exception :as exception]
[reitit.ring.middleware.multipart :as multipart]
[reitit.ring.middleware.parameters :as parameters]
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.spec :as spec]
; [spec-tools.spell :as spell]
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.validate.spec :as spec]
; [spec-tools.spell :as spell]
[ring.adapter.jetty :as jetty]
[muuntaja.core :as m]
[clojure.java.io :as io]
Expand Down
5 changes: 3 additions & 2 deletions examples/ring-spec-swagger/src/example/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
[reitit.ring.middleware.exception :as exception]
[reitit.ring.middleware.multipart :as multipart]
[reitit.ring.middleware.parameters :as parameters]
[reitit.ring.spec :as ring-spec]
;; Uncomment to use
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.spec :as spec]
; [reitit.ring.validate.spec :as spec]
; [spec-tools.spell :as spell]
[ring.adapter.jetty :as jetty]
[muuntaja.core :as m]
[clojure.spec.alpha :as s]
[clojure.java.io :as io]))

(s/def ::file multipart/temp-file-part)
(s/def ::file ring-spec/temp-file-part)
(s/def ::file-params (s/keys :req-un [::file]))

(s/def ::name string?)
Expand Down
5 changes: 3 additions & 2 deletions examples/ring-swagger/src/example/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
[reitit.ring.middleware.exception :as exception]
[reitit.ring.middleware.multipart :as multipart]
[reitit.ring.middleware.parameters :as parameters]
[reitit.ring.spec :as ring-spec]
;; Uncomment to use
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.spec :as spec]
; [reitit.ring.validate.spec :as spec]
; [spec-tools.spell :as spell]
[ring.adapter.jetty :as jetty]
[muuntaja.core :as m]
Expand All @@ -31,7 +32,7 @@

["/upload"
{:post {:summary "upload a file"
:parameters {:multipart {:file multipart/temp-file-part}}
:parameters {:multipart {:file ring-spec/temp-file-part}}
:responses {200 {:body {:name string?, :size int?}}}
:handler (fn [{{{:keys [file]} :multipart} :parameters}]
{:status 200
Expand Down
2 changes: 1 addition & 1 deletion modules/reitit-http/src/reitit/http/spec.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns reitit.http.spec
(:require [clojure.spec.alpha :as s]
[reitit.ring.spec :as rrs]
[reitit.ring.validate.spec :as rrs]
[reitit.interceptor :as interceptor]
[reitit.exception :as exception]
[reitit.spec :as rs]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
(ns reitit.ring.middleware.multipart
(:refer-clojure :exclude [compile])
(:require [reitit.coercion :as coercion]
[ring.middleware.multipart-params :as multipart-params]
[clojure.spec.alpha :as s]
[spec-tools.core :as st])
(:import (java.io File)))

(s/def ::filename string?)
(s/def ::content-type string?)
(s/def ::tempfile (partial instance? File))
(s/def ::bytes bytes?)
(s/def ::size int?)

(def temp-file-part
"Spec for file param created by ring.middleware.multipart-params.temp-file store."
(st/spec
{:spec (s/keys :req-un [::filename ::content-type ::tempfile ::size])
:swagger/type "file"}))

(def bytes-part
"Spec for file param created by ring.middleware.multipart-params.byte-array store."
(st/spec
{:spec (s/keys :req-un [::filename ::content-type ::bytes])
:swagger/type "file"}))
[ring.middleware.multipart-params :as multipart-params]))

(defn- coerced-request [request coercers]
(if-let [coerced (if coercers (coercion/coerce-request coercers request))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns reitit.ring.spec
(ns reitit.ring.validate.spec
(:require [clojure.spec.alpha :as s]
[reitit.middleware :as middleware]
[reitit.spec :as rs]
Expand Down
23 changes: 23 additions & 0 deletions modules/reitit-spec/src/reitit/ring/spec.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns reitit.ring.spec
(:require [spec-tools.core :as st]
[clojure.spec.alpha :as s])
(:import (java.io File)))

(s/def ::filename string?)
(s/def ::content-type string?)
(s/def ::tempfile (partial instance? File))
(s/def ::bytes bytes?)
(s/def ::size int?)

(def temp-file-part
"Spec for file param created by ring.middleware.multipart-params.temp-file store."
(st/spec
{:spec (s/keys :req-un [::filename ::content-type ::tempfile ::size])
:swagger/type "file"}))

(def bytes-part
"Spec for file param created by ring.middleware.multipart-params.byte-array store."
(st/spec
{:spec (s/keys :req-un [::filename ::content-type ::bytes])
:swagger/type "file"}))

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns reitit.ring-spec-test
(ns reitit.ring-validate-spec-test
(:require [clojure.test :refer [deftest testing is]]
[reitit.ring :as ring]
[reitit.ring.spec :as rrs]
[reitit.ring.validate.spec :as rrs]
[reitit.ring.coercion :as rrc]
[reitit.coercion.spec]
[clojure.spec.alpha :as s]
Expand Down Expand Up @@ -51,7 +51,7 @@
(testing "predicates are not allowed"
(is (thrown-with-msg?
ExceptionInfo
#":reitit.ring.spec/invalid-specs"
#":reitit.ring.validate.spec/invalid-specs"
(ring/router
["/api" {:handler "identity"}]
{:spec any?
Expand Down