mirror of
https://github.com/metosin/reitit.git
synced 2025-12-20 17:41:11 +00:00
Rename old reitit.ring.spec and move multipart specs to new ns
This commit is contained in:
parent
c4e84c2875
commit
ec21998478
10 changed files with 57 additions and 36 deletions
17
CHANGELOG.md
17
CHANGELOG.md
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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])
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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?)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]))
|
||||
|
|
|
|||
|
|
@ -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))]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
23
modules/reitit-spec/src/reitit/ring/spec.cljc
Normal file
23
modules/reitit-spec/src/reitit/ring/spec.cljc
Normal file
|
|
@ -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"}))
|
||||
|
||||
|
|
@ -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]
|
||||
|
|
@ -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?
|
||||
Loading…
Reference in a new issue