mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
fix spec tests + format
This commit is contained in:
parent
1247e7ff25
commit
8e1e7e62ca
25 changed files with 208 additions and 208 deletions
|
|
@ -14,6 +14,7 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
|
||||||
|
|
||||||
## UNRELEASED
|
## UNRELEASED
|
||||||
|
|
||||||
|
* **BREAKING**: Drop tests for Clojure 1.9, run tests with 1.10 & 1.11
|
||||||
* Add support for fragment parameters in the reitit-frontend module [#554](https://github.com/metosin/reitit/pull/554)
|
* Add support for fragment parameters in the reitit-frontend module [#554](https://github.com/metosin/reitit/pull/554)
|
||||||
* NEW option `:meta-merge` on a router for custom merge strategy on route data
|
* NEW option `:meta-merge` on a router for custom merge strategy on route data
|
||||||
* Swagger: support operationId in generated swagger json [#452](https://github.com/metosin/reitit/pull/452) & [#569](https://github.com/metosin/reitit/pull/569)
|
* Swagger: support operationId in generated swagger json [#452](https://github.com/metosin/reitit/pull/452) & [#569](https://github.com/metosin/reitit/pull/569)
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@
|
||||||
|
|
||||||
(defn interceptor-handler [router]
|
(defn interceptor-handler [router]
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn [path]
|
(fn [path]
|
||||||
(some->> (r/match-by-path router path)
|
(some->> (r/match-by-path router path)
|
||||||
:result
|
:result
|
||||||
:interceptors))
|
:interceptors))
|
||||||
{::router router}))
|
{::router router}))
|
||||||
|
|
|
||||||
|
|
@ -143,9 +143,9 @@
|
||||||
|
|
||||||
(defn middleware-handler [router]
|
(defn middleware-handler [router]
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn [path]
|
(fn [path]
|
||||||
(some->> path
|
(some->> path
|
||||||
(r/match-by-path router)
|
(r/match-by-path router)
|
||||||
:result
|
:result
|
||||||
:handler))
|
:handler))
|
||||||
{::router router}))
|
{::router router}))
|
||||||
|
|
|
||||||
|
|
@ -176,10 +176,10 @@
|
||||||
(fn [_ [p n]]
|
(fn [_ [p n]]
|
||||||
(if-let [cp (common-prefix p path)]
|
(if-let [cp (common-prefix p path)]
|
||||||
(if (= cp p)
|
(if (= cp p)
|
||||||
;; insert into child node
|
;; insert into child node
|
||||||
(let [n' (-insert n (conj ps (subs path (count p))) fp params data)]
|
(let [n' (-insert n (conj ps (subs path (count p))) fp params data)]
|
||||||
(reduced (assoc-in node [:children p] n')))
|
(reduced (assoc-in node [:children p] n')))
|
||||||
;; split child node
|
;; split child node
|
||||||
(let [rp (subs p (count cp))
|
(let [rp (subs p (count cp))
|
||||||
rp' (subs path (count cp))
|
rp' (subs path (count cp))
|
||||||
n' (-insert (-node {}) ps fp params data)
|
n' (-insert (-node {}) ps fp params data)
|
||||||
|
|
@ -189,7 +189,7 @@
|
||||||
(dissoc p)
|
(dissoc p)
|
||||||
(assoc cp n'')))))))))
|
(assoc cp n'')))))))))
|
||||||
nil (:children node))
|
nil (:children node))
|
||||||
;; new child node
|
;; new child node
|
||||||
(assoc-in node [:children path] (-insert (-node {}) ps fp params data))))]
|
(assoc-in node [:children path] (-insert (-node {}) ps fp params data))))]
|
||||||
(if-let [child (get-in node' [:children ""])]
|
(if-let [child (get-in node' [:children ""])]
|
||||||
;; optimize by removing empty paths
|
;; optimize by removing empty paths
|
||||||
|
|
@ -385,62 +385,62 @@
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(->
|
(->
|
||||||
[["/v2/whoami" 1]
|
[["/v2/whoami" 1]
|
||||||
["/v2/users/:user-id/datasets" 2]
|
["/v2/users/:user-id/datasets" 2]
|
||||||
["/v2/public/projects/:project-id/datasets" 3]
|
["/v2/public/projects/:project-id/datasets" 3]
|
||||||
["/v1/public/topics/:topic" 4]
|
["/v1/public/topics/:topic" 4]
|
||||||
["/v1/users/:user-id/orgs/:org-id" 5]
|
["/v1/users/:user-id/orgs/:org-id" 5]
|
||||||
["/v1/search/topics/:term" 6]
|
["/v1/search/topics/:term" 6]
|
||||||
["/v1/users/:user-id/invitations" 7]
|
["/v1/users/:user-id/invitations" 7]
|
||||||
["/v1/users/:user-id/topics" 9]
|
["/v1/users/:user-id/topics" 9]
|
||||||
["/v1/users/:user-id/bookmarks/followers" 10]
|
["/v1/users/:user-id/bookmarks/followers" 10]
|
||||||
["/v2/datasets/:dataset-id" 11]
|
["/v2/datasets/:dataset-id" 11]
|
||||||
["/v1/orgs/:org-id/usage-stats" 12]
|
["/v1/orgs/:org-id/usage-stats" 12]
|
||||||
["/v1/orgs/:org-id/devices/:client-id" 13]
|
["/v1/orgs/:org-id/devices/:client-id" 13]
|
||||||
["/v1/messages/user/:user-id" 14]
|
["/v1/messages/user/:user-id" 14]
|
||||||
["/v1/users/:user-id/devices" 15]
|
["/v1/users/:user-id/devices" 15]
|
||||||
["/v1/public/users/:user-id" 16]
|
["/v1/public/users/:user-id" 16]
|
||||||
["/v1/orgs/:org-id/errors" 17]
|
["/v1/orgs/:org-id/errors" 17]
|
||||||
["/v1/public/orgs/:org-id" 18]
|
["/v1/public/orgs/:org-id" 18]
|
||||||
["/v1/orgs/:org-id/invitations" 19]
|
["/v1/orgs/:org-id/invitations" 19]
|
||||||
["/v1/users/:user-id/device-errors" 22]
|
["/v1/users/:user-id/device-errors" 22]
|
||||||
["/v2/login" 23]
|
["/v2/login" 23]
|
||||||
["/v1/users/:user-id/usage-stats" 24]
|
["/v1/users/:user-id/usage-stats" 24]
|
||||||
["/v2/users/:user-id/devices" 25]
|
["/v2/users/:user-id/devices" 25]
|
||||||
["/v1/users/:user-id/claim-device/:client-id" 26]
|
["/v1/users/:user-id/claim-device/:client-id" 26]
|
||||||
["/v2/public/projects/:project-id" 27]
|
["/v2/public/projects/:project-id" 27]
|
||||||
["/v2/public/datasets/:dataset-id" 28]
|
["/v2/public/datasets/:dataset-id" 28]
|
||||||
["/v2/users/:user-id/topics/bulk" 29]
|
["/v2/users/:user-id/topics/bulk" 29]
|
||||||
["/v1/messages/device/:client-id" 30]
|
["/v1/messages/device/:client-id" 30]
|
||||||
["/v1/users/:user-id/owned-orgs" 31]
|
["/v1/users/:user-id/owned-orgs" 31]
|
||||||
["/v1/topics/:topic" 32]
|
["/v1/topics/:topic" 32]
|
||||||
["/v1/users/:user-id/bookmark/:topic" 33]
|
["/v1/users/:user-id/bookmark/:topic" 33]
|
||||||
["/v1/orgs/:org-id/members/:user-id" 34]
|
["/v1/orgs/:org-id/members/:user-id" 34]
|
||||||
["/v1/users/:user-id/devices/:client-id" 35]
|
["/v1/users/:user-id/devices/:client-id" 35]
|
||||||
["/v1/users/:user-id" 36]
|
["/v1/users/:user-id" 36]
|
||||||
["/v1/orgs/:org-id/devices" 37]
|
["/v1/orgs/:org-id/devices" 37]
|
||||||
["/v1/orgs/:org-id/members" 38]
|
["/v1/orgs/:org-id/members" 38]
|
||||||
["/v2/orgs/:org-id/topics" 40]
|
["/v2/orgs/:org-id/topics" 40]
|
||||||
["/v1/whoami" 41]
|
["/v1/whoami" 41]
|
||||||
["/v1/orgs/:org-id" 42]
|
["/v1/orgs/:org-id" 42]
|
||||||
["/v1/users/:user-id/api-key" 43]
|
["/v1/users/:user-id/api-key" 43]
|
||||||
["/v2/schemas" 44]
|
["/v2/schemas" 44]
|
||||||
["/v2/users/:user-id/topics" 45]
|
["/v2/users/:user-id/topics" 45]
|
||||||
["/v1/orgs/:org-id/confirm-membership/:token" 46]
|
["/v1/orgs/:org-id/confirm-membership/:token" 46]
|
||||||
["/v2/topics/:topic" 47]
|
["/v2/topics/:topic" 47]
|
||||||
["/v1/messages/topic/:topic" 48]
|
["/v1/messages/topic/:topic" 48]
|
||||||
["/v1/users/:user-id/devices/:client-id/reset-password" 49]
|
["/v1/users/:user-id/devices/:client-id/reset-password" 49]
|
||||||
["/v2/topics" 50]
|
["/v2/topics" 50]
|
||||||
["/v1/login" 51]
|
["/v1/login" 51]
|
||||||
["/v1/users/:user-id/orgs" 52]
|
["/v1/users/:user-id/orgs" 52]
|
||||||
["/v2/public/messages/dataset/:dataset-id" 53]
|
["/v2/public/messages/dataset/:dataset-id" 53]
|
||||||
["/v1/topics" 54]
|
["/v1/topics" 54]
|
||||||
["/v1/orgs" 55]
|
["/v1/orgs" 55]
|
||||||
["/v1/users/:user-id/bookmarks" 56]
|
["/v1/users/:user-id/bookmarks" 56]
|
||||||
["/v1/orgs/:org-id/topics" 57]
|
["/v1/orgs/:org-id/topics" 57]
|
||||||
["/command1 {arg1} {arg2}" ::cmd1]
|
["/command1 {arg1} {arg2}" ::cmd1]
|
||||||
["/command2 {arg1} {arg2} {arg3}" ::cmd2]]
|
["/command2 {arg1} {arg2} {arg3}" ::cmd2]]
|
||||||
(insert)
|
(insert)
|
||||||
(compile)
|
(compile)
|
||||||
(pretty)))
|
(pretty)))
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
[fipp.engine]
|
[fipp.engine]
|
||||||
[fipp.visit]
|
[fipp.visit]
|
||||||
[reitit.exception :as exception]
|
[reitit.exception :as exception]
|
||||||
[spell-spec.expound] ;; expound
|
[spell-spec.expound])) ;; expound
|
||||||
))
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; colors
|
;; colors
|
||||||
|
|
@ -46,17 +45,17 @@
|
||||||
:error 196})
|
:error 196})
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(defn- -color [color & text]
|
(defn- -color [color & text]
|
||||||
(str "\033[38;5;" (colors color color) "m" (apply str text) "\u001B[0m"))
|
(str "\033[38;5;" (colors color color) "m" (apply str text) "\u001B[0m"))
|
||||||
|
|
||||||
(doseq [c (range 0 255)]
|
(doseq [c (range 0 255)]
|
||||||
(println (-color c "kikka") "->" c))
|
(println (-color c "kikka") "->" c))
|
||||||
|
|
||||||
(doseq [[n c] colors]
|
(doseq [[n c] colors]
|
||||||
(println (-color c "kikka") "->" c n))
|
(println (-color c "kikka") "->" c n))
|
||||||
|
|
||||||
(doseq [[k v] expound.ansi/sgr-code]
|
(doseq [[k v] expound.ansi/sgr-code]
|
||||||
(println (expound.ansi/sgr "kikka" k) "->" k)))
|
(println (expound.ansi/sgr "kikka" k) "->" k)))
|
||||||
|
|
||||||
(defn- -start [x] (str "\033[38;5;" x "m"))
|
(defn- -start [x] (str "\033[38;5;" x "m"))
|
||||||
(defn- -end [] "\u001B[0m")
|
(defn- -end [] "\u001B[0m")
|
||||||
|
|
@ -220,10 +219,10 @@
|
||||||
(defn exception [e]
|
(defn exception [e]
|
||||||
(let [data (-> e ex-data :data)
|
(let [data (-> e ex-data :data)
|
||||||
message (format-exception (-> e ex-data :type) #?(:clj (.getMessage ^Exception e) :cljs (ex-message e)) data)
|
message (format-exception (-> e ex-data :type) #?(:clj (.getMessage ^Exception e) :cljs (ex-message e)) data)
|
||||||
source #?(:clj (->> e Throwable->map :trace
|
source #?(:clj (->> e Throwable->map :trace
|
||||||
(drop-while #(not= (name (first %)) "reitit.core$router"))
|
(drop-while #(not= (name (first %)) "reitit.core$router"))
|
||||||
(drop-while #(= (name (first %)) "reitit.core$router"))
|
(drop-while #(= (name (first %)) "reitit.core$router"))
|
||||||
next first source-str)
|
next first source-str)
|
||||||
:cljs "unknown")]
|
:cljs "unknown")]
|
||||||
(ex-info (exception-str message source (printer)) (assoc (or data {}) ::exception/cause e))))
|
(ex-info (exception-str message source (printer)) (assoc (or data {}) ::exception/cause e))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,35 +138,35 @@
|
||||||
enrich-request (ring/create-enrich-request inject-match? inject-router?)
|
enrich-request (ring/create-enrich-request inject-match? inject-router?)
|
||||||
enrich-default-request (ring/create-enrich-default-request inject-router?)]
|
enrich-default-request (ring/create-enrich-default-request inject-router?)]
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn
|
(fn
|
||||||
([request]
|
([request]
|
||||||
(if-let [match (r/match-by-path router (:uri request))]
|
(if-let [match (r/match-by-path router (:uri request))]
|
||||||
(let [method (:request-method request)
|
(let [method (:request-method request)
|
||||||
path-params (:path-params match)
|
path-params (:path-params match)
|
||||||
endpoint (-> match :result method)
|
endpoint (-> match :result method)
|
||||||
interceptors (or (:queue endpoint) (:interceptors endpoint))
|
interceptors (or (:queue endpoint) (:interceptors endpoint))
|
||||||
request (enrich-request request path-params match router)]
|
request (enrich-request request path-params match router)]
|
||||||
(or (interceptor/execute executor interceptors request)
|
(or (interceptor/execute executor interceptors request)
|
||||||
(interceptor/execute executor default-queue request)))
|
(interceptor/execute executor default-queue request)))
|
||||||
(interceptor/execute executor default-queue (enrich-default-request request router))))
|
(interceptor/execute executor default-queue (enrich-default-request request router))))
|
||||||
([request respond raise]
|
([request respond raise]
|
||||||
(let [default #(interceptor/execute executor default-queue % respond raise)]
|
(let [default #(interceptor/execute executor default-queue % respond raise)]
|
||||||
(if-let [match (r/match-by-path router (:uri request))]
|
(if-let [match (r/match-by-path router (:uri request))]
|
||||||
(let [method (:request-method request)
|
(let [method (:request-method request)
|
||||||
path-params (:path-params match)
|
path-params (:path-params match)
|
||||||
endpoint (-> match :result method)
|
endpoint (-> match :result method)
|
||||||
interceptors (or (:queue endpoint) (:interceptors endpoint))
|
interceptors (or (:queue endpoint) (:interceptors endpoint))
|
||||||
request (enrich-request request path-params match router)
|
request (enrich-request request path-params match router)
|
||||||
respond' (fn [response]
|
respond' (fn [response]
|
||||||
(if response
|
(if response
|
||||||
(respond response)
|
(respond response)
|
||||||
(default request)))]
|
(default request)))]
|
||||||
(if interceptors
|
(if interceptors
|
||||||
(interceptor/execute executor interceptors request respond' raise)
|
(interceptor/execute executor interceptors request respond' raise)
|
||||||
(default request)))
|
(default request)))
|
||||||
(default (enrich-default-request request router))))
|
(default (enrich-default-request request router))))
|
||||||
nil))
|
nil))
|
||||||
{::r/router router}))))
|
{::r/router router}))))
|
||||||
|
|
||||||
(defn get-router [handler]
|
(defn get-router [handler]
|
||||||
(-> handler meta ::r/router))
|
(-> handler meta ::r/router))
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@
|
||||||
show? (fn [key] (contains? error-keys key))
|
show? (fn [key] (contains? error-keys key))
|
||||||
transformers (walk/prewalk #(if (satisfies? TransformationProvider %) (-transformer % opts) %) transformers)
|
transformers (walk/prewalk #(if (satisfies? TransformationProvider %) (-transformer % opts) %) transformers)
|
||||||
compile (if lite (fn [schema options] (compile (binding [l/*options* options] (l/schema schema)) options))
|
compile (if lite (fn [schema options] (compile (binding [l/*options* options] (l/schema schema)) options))
|
||||||
compile)]
|
compile)]
|
||||||
^{:type ::coercion/coercion}
|
^{:type ::coercion/coercion}
|
||||||
(reify coercion/Coercion
|
(reify coercion/Coercion
|
||||||
(-get-name [_] :malli)
|
(-get-name [_] :malli)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(ns reitit.ring
|
(ns reitit.ring
|
||||||
(:require [clojure.string :as str]
|
(:require [clojure.string :as str]
|
||||||
#?@(:clj [[ring.util.mime-type :as mime-type]
|
#?@(:clj [[ring.util.mime-type :as mime-type]
|
||||||
[ring.util.response :as response]])
|
[ring.util.response :as response]])
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.exception :as ex]
|
[reitit.exception :as ex]
|
||||||
[reitit.impl :as impl]
|
[reitit.impl :as impl]
|
||||||
|
|
@ -316,28 +316,28 @@
|
||||||
enrich-request (create-enrich-request inject-match? inject-router?)
|
enrich-request (create-enrich-request inject-match? inject-router?)
|
||||||
enrich-default-request (create-enrich-default-request inject-router?)]
|
enrich-default-request (create-enrich-default-request inject-router?)]
|
||||||
(with-meta
|
(with-meta
|
||||||
(wrap
|
(wrap
|
||||||
(fn
|
(fn
|
||||||
([request]
|
([request]
|
||||||
(if-let [match (r/match-by-path router (:uri request))]
|
(if-let [match (r/match-by-path router (:uri request))]
|
||||||
(let [method (:request-method request)
|
(let [method (:request-method request)
|
||||||
path-params (:path-params match)
|
path-params (:path-params match)
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler (-> result method :handler (or default-handler))
|
handler (-> result method :handler (or default-handler))
|
||||||
request (enrich-request request path-params match router)]
|
request (enrich-request request path-params match router)]
|
||||||
(or (handler request) (default-handler request)))
|
(or (handler request) (default-handler request)))
|
||||||
(default-handler (enrich-default-request request router))))
|
(default-handler (enrich-default-request request router))))
|
||||||
([request respond raise]
|
([request respond raise]
|
||||||
(if-let [match (r/match-by-path router (:uri request))]
|
(if-let [match (r/match-by-path router (:uri request))]
|
||||||
(let [method (:request-method request)
|
(let [method (:request-method request)
|
||||||
path-params (:path-params match)
|
path-params (:path-params match)
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler (-> result method :handler (or default-handler))
|
handler (-> result method :handler (or default-handler))
|
||||||
request (enrich-request request path-params match router)]
|
request (enrich-request request path-params match router)]
|
||||||
((routes handler default-handler) request respond raise))
|
((routes handler default-handler) request respond raise))
|
||||||
(default-handler (enrich-default-request request router) respond raise))
|
(default-handler (enrich-default-request request router) respond raise))
|
||||||
nil)))
|
nil)))
|
||||||
{::r/router router}))))
|
{::r/router router}))))
|
||||||
|
|
||||||
(defn get-router [handler]
|
(defn get-router [handler]
|
||||||
(-> handler meta ::r/router))
|
(-> handler meta ::r/router))
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
(-get-name [_] :schema)
|
(-get-name [_] :schema)
|
||||||
(-get-options [_] opts)
|
(-get-options [_] opts)
|
||||||
(-get-apidocs [this specification {:keys [parameters responses]}]
|
(-get-apidocs [this specification {:keys [parameters responses]}]
|
||||||
;; TODO: this looks identical to spec, refactor when schema is done.
|
;; TODO: this looks identical to spec, refactor when schema is done.
|
||||||
(case specification
|
(case specification
|
||||||
:swagger (swagger/swagger-spec
|
:swagger (swagger/swagger-spec
|
||||||
(merge
|
(merge
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,13 @@
|
||||||
(if (and data (not no-doc))
|
(if (and data (not no-doc))
|
||||||
[method
|
[method
|
||||||
(meta-merge
|
(meta-merge
|
||||||
base-swagger-spec
|
base-swagger-spec
|
||||||
(apply meta-merge (keep (comp :swagger :data) middleware))
|
(apply meta-merge (keep (comp :swagger :data) middleware))
|
||||||
(apply meta-merge (keep (comp :swagger :data) interceptors))
|
(apply meta-merge (keep (comp :swagger :data) interceptors))
|
||||||
(if coercion
|
(if coercion
|
||||||
(coercion/get-apidocs coercion :swagger data))
|
(coercion/get-apidocs coercion :swagger data))
|
||||||
(select-keys data [:tags :summary :description :operationId])
|
(select-keys data [:tags :summary :description :operationId])
|
||||||
(strip-top-level-keys swagger))]))
|
(strip-top-level-keys swagger))]))
|
||||||
transform-path (fn [[p _ c]]
|
transform-path (fn [[p _ c]]
|
||||||
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]
|
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]
|
||||||
[(swagger-path p (r/options router)) endpoint]))
|
[(swagger-path p (r/options router)) endpoint]))
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
|
|
||||||
:java-source-paths ["modules/reitit-core/java-src"]
|
:java-source-paths ["modules/reitit-core/java-src"]
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.10.2"]
|
:dependencies [[org.clojure/clojure "1.11.1"]
|
||||||
[org.clojure/clojurescript "1.10.773"]
|
[org.clojure/clojurescript "1.10.773"]
|
||||||
|
|
||||||
;; modules dependencies
|
;; modules dependencies
|
||||||
|
|
@ -115,7 +115,7 @@
|
||||||
[ring-cors "0.1.13"]
|
[ring-cors "0.1.13"]
|
||||||
|
|
||||||
[com.bhauman/rebel-readline "0.1.4"]]}
|
[com.bhauman/rebel-readline "0.1.4"]]}
|
||||||
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
|
:1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]}
|
||||||
:perf {:jvm-opts ^:replace ["-server"
|
:perf {:jvm-opts ^:replace ["-server"
|
||||||
"-Xmx4096m"
|
"-Xmx4096m"
|
||||||
"-Dclojure.compiler.direct-linking=true"]
|
"-Dclojure.compiler.direct-linking=true"]
|
||||||
|
|
@ -141,7 +141,7 @@
|
||||||
"-XX:+PrintCompilation"
|
"-XX:+PrintCompilation"
|
||||||
"-XX:+UnlockDiagnosticVMOptions"
|
"-XX:+UnlockDiagnosticVMOptions"
|
||||||
"-XX:+PrintInlining"]}}
|
"-XX:+PrintInlining"]}}
|
||||||
:aliases {"all" ["with-profile" "dev,default:dev,default,1.9"]
|
:aliases {"all" ["with-profile" "dev,default:dev,default,1.10"]
|
||||||
"perf" ["with-profile" "default,dev,perf"]
|
"perf" ["with-profile" "default,dev,perf"]
|
||||||
"test-clj" ["all" "do" ["bat-test"] ["check"]]
|
"test-clj" ["all" "do" ["bat-test"] ["check"]]
|
||||||
"test-browser" ["doo" "chrome-headless" "test"]
|
"test-browser" ["doo" "chrome-headless" "test"]
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,4 @@
|
||||||
(spit "doc/cljdoc.edn" (with-out-str (pprint/pprint data)))))
|
(spit "doc/cljdoc.edn" (with-out-str (pprint/pprint data)))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(reap!))
|
(reap!))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(ns reitit.exception-test
|
(ns reitit.exception-test
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[clojure.test :refer [are deftest is testing]]
|
[clojure.test :refer [are deftest is]]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.dev.pretty :as pretty]
|
[reitit.dev.pretty :as pretty]
|
||||||
[reitit.exception :as exception]
|
[reitit.exception :as exception]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns reitit.impl-test
|
(ns reitit.impl-test
|
||||||
(:require [clojure.test :refer [are deftest is testing]]
|
(:require [clojure.test :refer [are deftest is]]
|
||||||
[reitit.impl :as impl]))
|
[reitit.impl :as impl]))
|
||||||
|
|
||||||
(deftest strip-nils-test
|
(deftest strip-nils-test
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns reitit.interceptor-test
|
(ns reitit.interceptor-test
|
||||||
(:require [clojure.test :refer [are deftest is testing]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.interceptor :as interceptor])
|
[reitit.interceptor :as interceptor])
|
||||||
#?(:clj
|
#?(:clj
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns reitit.middleware-test
|
(ns reitit.middleware-test
|
||||||
(:require [clojure.test :refer [are deftest is testing]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.middleware :as middleware])
|
[reitit.middleware :as middleware])
|
||||||
#?(:clj
|
#?(:clj
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
(:require [clojure.test :refer [deftest is testing]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[malli.experimental.lite :as l]
|
[malli.experimental.lite :as l]
|
||||||
#?@(:clj [[muuntaja.middleware]
|
#?@(:clj [[muuntaja.middleware]
|
||||||
[jsonista.core :as j]])
|
[jsonista.core :as j]])
|
||||||
[malli.core :as m]
|
[malli.core :as m]
|
||||||
[malli.util :as mu]
|
[malli.util :as mu]
|
||||||
[meta-merge.core :refer [meta-merge]]
|
[meta-merge.core :refer [meta-merge]]
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Invalid route data"
|
#"Invalid route data"
|
||||||
(ring/router
|
(ring/router
|
||||||
["/api" {:handler identity
|
["/api" {:handler identity
|
||||||
:middleware '()}]
|
:middleware '()}]
|
||||||
{:validate rrs/validate})))))
|
{:validate rrs/validate})))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -733,6 +733,6 @@
|
||||||
{::trie/trie-compiler compiler})]
|
{::trie/trie-compiler compiler})]
|
||||||
(dotimes [_ 10]
|
(dotimes [_ 10]
|
||||||
(future
|
(future
|
||||||
(dotimes [n 100000]
|
(dotimes [n 100000]
|
||||||
(let [body (:body (app {:request-method :get, :uri (str "/" n)}))]
|
(let [body (:body (app {:request-method :get, :uri (str "/" n)}))]
|
||||||
(is (= body (str n))))))))))))
|
(is (= body (str n))))))))))))
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
(are [data]
|
(are [data]
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Call to #'reitit.core/router did not conform to spec"
|
#"Call to (#')*reitit.core/router did not conform to spec"
|
||||||
(r/router
|
(r/router
|
||||||
data)))
|
data)))
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
(are [opts]
|
(are [opts]
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Call to #'reitit.core/router did not conform to spec"
|
#"Call to (#')*reitit.core/router did not conform to spec"
|
||||||
(r/router
|
(r/router
|
||||||
["/api"] opts)))
|
["/api"] opts)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,35 +22,35 @@
|
||||||
:swagger {:info {:title "my-api"}}
|
:swagger {:info {:title "my-api"}}
|
||||||
:handler (swagger/create-swagger-handler)}}]
|
:handler (swagger/create-swagger-handler)}}]
|
||||||
|
|
||||||
["/spec" {:coercion spec/coercion}
|
["/spec" {:coercion spec/coercion}
|
||||||
["/plus/:z"
|
["/plus/:z"
|
||||||
{:patch {:summary "patch"
|
{:patch {:summary "patch"
|
||||||
:operationId "Patch"
|
:operationId "Patch"
|
||||||
|
:handler (constantly {:status 200})}
|
||||||
|
:options {:summary "options"
|
||||||
|
:middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}]
|
||||||
:handler (constantly {:status 200})}
|
:handler (constantly {:status 200})}
|
||||||
:options {:summary "options"
|
:get {:summary "plus"
|
||||||
:middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}]
|
:operationId "GetPlus"
|
||||||
:handler (constantly {:status 200})}
|
:parameters {:query {:x int?, :y int?}
|
||||||
:get {:summary "plus"
|
:path {:z int?}}
|
||||||
:operationId "GetPlus"
|
:swagger {:responses {400 {:schema {:type "string"}
|
||||||
:parameters {:query {:x int?, :y int?}
|
:description "kosh"}}}
|
||||||
:path {:z int?}}
|
:responses {200 {:body {:total int?}}
|
||||||
:swagger {:responses {400 {:schema {:type "string"}
|
500 {:description "fail"}}
|
||||||
:description "kosh"}}}
|
:handler (fn [{{{:keys [x y]} :query
|
||||||
:responses {200 {:body {:total int?}}
|
{:keys [z]} :path} :parameters}]
|
||||||
500 {:description "fail"}}
|
{:status 200, :body {:total (+ x y z)}})}
|
||||||
:handler (fn [{{{:keys [x y]} :query
|
:post {:summary "plus with body"
|
||||||
{:keys [z]} :path} :parameters}]
|
:parameters {:body (ds/maybe [int?])
|
||||||
{:status 200, :body {:total (+ x y z)}})}
|
:path {:z int?}}
|
||||||
:post {:summary "plus with body"
|
:swagger {:responses {400 {:schema {:type "string"}
|
||||||
:parameters {:body (ds/maybe [int?])
|
:description "kosh"}}}
|
||||||
:path {:z int?}}
|
:responses {200 {:body {:total int?}}
|
||||||
:swagger {:responses {400 {:schema {:type "string"}
|
500 {:description "fail"}}
|
||||||
:description "kosh"}}}
|
:handler (fn [{{{:keys [z]} :path
|
||||||
:responses {200 {:body {:total int?}}
|
xs :body} :parameters}]
|
||||||
500 {:description "fail"}}
|
{:status 200, :body {:total (+ (reduce + xs) z)}})}}]]
|
||||||
:handler (fn [{{{:keys [z]} :path
|
|
||||||
xs :body} :parameters}]
|
|
||||||
{:status 200, :body {:total (+ (reduce + xs) z)}})}}]]
|
|
||||||
|
|
||||||
["/malli" {:coercion malli/coercion}
|
["/malli" {:coercion malli/coercion}
|
||||||
["/plus/*z"
|
["/plus/*z"
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@
|
||||||
(let [log (atom [])
|
(let [log (atom [])
|
||||||
controller-state (atom [])
|
controller-state (atom [])
|
||||||
controller-1 {:start (fn [_] (swap! log conj :start-1))
|
controller-1 {:start (fn [_] (swap! log conj :start-1))
|
||||||
:stop (fn [_] (swap! log conj :stop-1))}
|
:stop (fn [_] (swap! log conj :stop-1))}
|
||||||
controller-2 {:start (fn [_] (swap! log conj :start-2))
|
controller-2 {:start (fn [_] (swap! log conj :start-2))
|
||||||
:stop (fn [_] (swap! log conj :stop-2))}
|
:stop (fn [_] (swap! log conj :stop-2))}
|
||||||
controller-3 {:start (fn [{:keys [foo]}] (swap! log conj [:start-3 foo]))
|
controller-3 {:start (fn [{:keys [foo]}] (swap! log conj [:start-3 foo]))
|
||||||
:stop (fn [{:keys [foo]}] (swap! log conj [:stop-3 foo]))
|
:stop (fn [{:keys [foo]}] (swap! log conj [:stop-3 foo]))
|
||||||
:identity (fn [match]
|
:identity (fn [match]
|
||||||
{:foo (-> match :parameters :path :foo)})}]
|
{:foo (-> match :parameters :path :foo)})}]
|
||||||
|
|
||||||
|
|
@ -70,9 +70,9 @@
|
||||||
(let [log (atom [])
|
(let [log (atom [])
|
||||||
controller-state (atom [])
|
controller-state (atom [])
|
||||||
static {:start (fn [params] (swap! log conj [:start-static]))
|
static {:start (fn [params] (swap! log conj [:start-static]))
|
||||||
:stop (fn [params] (swap! log conj [:stop-static]))}
|
:stop (fn [params] (swap! log conj [:stop-static]))}
|
||||||
controller {:start (fn [params] (swap! log conj [:start params]))
|
controller {:start (fn [params] (swap! log conj [:start params]))
|
||||||
:stop (fn [params] (swap! log conj [:stop params]))
|
:stop (fn [params] (swap! log conj [:stop params]))
|
||||||
:parameters {:path [:foo]}}]
|
:parameters {:path [:foo]}}]
|
||||||
|
|
||||||
(testing "init"
|
(testing "init"
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,9 @@
|
||||||
(is (= [{:type :warn
|
(is (= [{:type :warn
|
||||||
:message ["missing route" ::asd]}]
|
:message ["missing route" ::asd]}]
|
||||||
(:messages
|
(:messages
|
||||||
(capture-console
|
(capture-console
|
||||||
(fn []
|
(fn []
|
||||||
(rf/match-by-name! router ::asd)))))))))
|
(rf/match-by-name! router ::asd)))))))))
|
||||||
|
|
||||||
(testing "schema coercion"
|
(testing "schema coercion"
|
||||||
(let [router (r/router ["/"
|
(let [router (r/router ["/"
|
||||||
|
|
@ -124,6 +124,6 @@
|
||||||
:required #{:id}
|
:required #{:id}
|
||||||
:path-params {}}]}]
|
:path-params {}}]}]
|
||||||
(:messages
|
(:messages
|
||||||
(capture-console
|
(capture-console
|
||||||
(fn []
|
(fn []
|
||||||
(rf/match-by-name! router ::foo {}))))))))))
|
(rf/match-by-name! router ::foo {}))))))))))
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
(is (= "#/bar/5?q=x"
|
(is (= "#/bar/5?q=x"
|
||||||
(rfh/href history ::bar {:id 5} {:q "x"})))
|
(rfh/href history ::bar {:id 5} {:q "x"})))
|
||||||
(let [{:keys [value messages]} (capture-console
|
(let [{:keys [value messages]} (capture-console
|
||||||
(fn []
|
(fn []
|
||||||
(rfh/href history ::asd)))]
|
(rfh/href history ::asd)))]
|
||||||
(is (= nil value))
|
(is (= nil value))
|
||||||
(is (= [{:type :warn
|
(is (= [{:type :warn
|
||||||
:message ["missing route" ::asd]}]
|
:message ["missing route" ::asd]}]
|
||||||
|
|
@ -84,8 +84,8 @@
|
||||||
(is (= "/bar/5?q=x"
|
(is (= "/bar/5?q=x"
|
||||||
(rfh/href history ::bar {:id 5} {:q "x"})))
|
(rfh/href history ::bar {:id 5} {:q "x"})))
|
||||||
(let [{:keys [value messages]} (capture-console
|
(let [{:keys [value messages]} (capture-console
|
||||||
(fn []
|
(fn []
|
||||||
(rfh/href history ::asd)))]
|
(rfh/href history ::asd)))]
|
||||||
(is (= nil value))
|
(is (= nil value))
|
||||||
(is (= [{:type :warn
|
(is (= [{:type :warn
|
||||||
:message ["missing route" ::asd]}]
|
:message ["missing route" ::asd]}]
|
||||||
|
|
@ -153,7 +153,7 @@
|
||||||
(done)))))
|
(done)))))
|
||||||
{:use-fragment false})
|
{:use-fragment false})
|
||||||
create-link #(doto
|
create-link #(doto
|
||||||
(js/document.createElement "A")
|
(js/document.createElement "A")
|
||||||
(.setAttribute "href" (rfh/href history ::foo)))
|
(.setAttribute "href" (rfh/href history ::foo)))
|
||||||
document-link (create-link)
|
document-link (create-link)
|
||||||
shadow-link (create-link)]
|
shadow-link (create-link)]
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@
|
||||||
(set! js/console.warn (partial log :warn))
|
(set! js/console.warn (partial log :warn))
|
||||||
(f)
|
(f)
|
||||||
(finally
|
(finally
|
||||||
(set! js/console.warn original-console-warn)))]
|
(set! js/console.warn original-console-warn)))]
|
||||||
{:value value
|
{:value value
|
||||||
:messages @messages}))
|
:messages @messages}))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue