Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{;;:skip-comments true
:lint-as {potemkin/def-derived-map clojure.core/defrecord}
:lint-as {potemkin/def-derived-map clojure.core/defrecord
clojure.test.check.clojure-test/defspec clojure.test/deftest}
:linters {:missing-else-branch {:level :off}
:unused-binding {:level :off}
:unused-referred-var {:exclude {clojure.test [deftest testing is are]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ jobs:
uses: DeLaGuardo/[email protected]
with:
lein: 2.9.5
clj-kondo: 2025.12.23

# Install openapi-schema-validator for openapi-tests
# Uses node version from the ubuntu-latest
- name: Install dependencies
run: npm ci

- name: Run Linter
run: ./lint.sh

- name: Run tests
run: ./scripts/test.sh clj

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns frontend-re-frame.core
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[reagent.dom :as rd]
[reitit.core :as r]
[reitit.coercion.spec :as rss]
Expand Down
1 change: 0 additions & 1 deletion examples/openapi/src/example/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[reitit.ring.middleware.multipart :as multipart]
[reitit.ring.middleware.parameters :as parameters]
[ring.adapter.jetty :as jetty]
[malli.core :as malli]
[muuntaja.core :as m]))

(def Transaction
Expand Down
2 changes: 1 addition & 1 deletion modules/reitit-core/src/reitit/coercion.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
(if coercer
(let [result (coercer query-params :default)]
(if (error? result)
(throw (ex-info (str "Query parameters coercion failed")
(throw (ex-info "Query parameters coercion failed"
result))
result))
query-params))))
Expand Down
4 changes: 4 additions & 0 deletions modules/reitit-core/src/reitit/exception.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
([type data]
(throw (ex-info (str type) {:type type, :data data}))))

(defn unsupported-protocol-method!
[method]
(fail! :unsupported-protocol-method {:method method}))

(defn get-message [e]
#?(:clj (.getMessage ^Exception e) :cljs (ex-message e)))

Expand Down
3 changes: 1 addition & 2 deletions modules/reitit-core/src/reitit/impl.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns ^:no-doc reitit.impl
#?(:cljs (:require-macros [reitit.impl]))
(:require [clojure.set :as set]
[clojure.string :as str]
(:require [clojure.string :as str]
[meta-merge.core :as mm]
[reitit.exception :as ex]
[reitit.trie :as trie])
Expand Down
4 changes: 2 additions & 2 deletions modules/reitit-dev/src/reitit/dev/pretty.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
;; TODO: this is hack, but seems to work and is safe.
(defn source-str [[target _ file line]]
(try
(if (and (not= 1 line))
(if (not= 1 line)
(let [file-name (str/replace file #"(.*?)\.\S[^\.]+" "$1")
target-name (name target)
ns (str (subs target-name 0 (or (str/index-of target-name (str file-name "$")) 0)) file-name)]
Expand All @@ -190,7 +190,7 @@
(color :title message " ")
(color :title-dark (repeat-str "-" between) " ")
(color :title source) " "
(color :title-dark (str "--"))]))
(color :title-dark "--")]))

(defn footer [{:keys [width]}]
(color :title-dark (repeat-str "-" width)))
Expand Down
12 changes: 6 additions & 6 deletions modules/reitit-http/src/reitit/http.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
compile (fn [[path data] opts scope]
(interceptor/compile-result [path data] opts scope))
->endpoint (fn [p d m s]
(let [d (ring/-compile-coercion d)]
(let [compiled (compile [p d] opts s)]
(-> compiled
(map->Endpoint)
(assoc :path p)
(assoc :method m)))))
(let [d (ring/-compile-coercion d)
compiled (compile [p d] opts s)]
(-> compiled
(map->Endpoint)
(assoc :path p)
(assoc :method m))))
->methods (fn [any? data]
(reduce
(fn [acc method]
Expand Down
10 changes: 7 additions & 3 deletions modules/reitit-pedestal/src/reitit/pedestal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(:require [io.pedestal.http :as http]
[io.pedestal.interceptor :as interceptor]
[io.pedestal.interceptor.chain :as chain]
[reitit.exception :as ex]
[reitit.http]
[reitit.interceptor])
(:import (java.lang.reflect Method)
(reitit.interceptor Executor)))
(:import (java.lang.reflect Method)))

;; TODO: variadic
(defn- arities [f]
Expand Down Expand Up @@ -46,12 +46,16 @@

(def pedestal-executor
(reify
Executor
reitit.interceptor/Executor
(queue [_ interceptors]
(->> interceptors
(map (fn [{::interceptor/keys [handler] :as interceptor}]
(or handler interceptor)))
(keep ->interceptor)))
(execute [_ _ _]
(ex/unsupported-protocol-method! 'reitit.interceptor/execute))
(execute [_ _ _ _ _]
(ex/unsupported-protocol-method! 'reitit.interceptor/execute))
(enqueue [_ context interceptors]
(chain/enqueue context interceptors))))

Expand Down
7 changes: 5 additions & 2 deletions modules/reitit-sieppari/src/reitit/interceptor/sieppari.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns reitit.interceptor.sieppari
(:require [reitit.interceptor :as interceptor]
(:require [reitit.exception :as ex]
[reitit.interceptor :as interceptor]
[sieppari.core :as sieppari]
[sieppari.queue :as queue]))

Expand All @@ -15,4 +16,6 @@
(execute [_ interceptors request]
(sieppari/execute interceptors request))
(execute [_ interceptors request respond raise]
(sieppari/execute interceptors request respond raise))))
(sieppari/execute interceptors request respond raise))
(enqueue [_ _ _]
(ex/unsupported-protocol-method! 'reitit.interceptor/enqueue))))
5 changes: 4 additions & 1 deletion perf-test/clj/reitit/coercion_perf_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@
(defrecord NoOpCoercion []
coercion/Coercion
(-get-name [_] :no-op)
(-get-options [_])
(-get-apidocs [_ _ {:keys [parameters responses] :as info}])
(-get-model-apidocs [_ _ _ _])
(-compile-model [_ model _] model)
(-open-model [_ spec] spec)
(-encode-error [_ error] error)
(-request-coercer [_ type spec] (fn [value format] value))
(-response-coercer [this spec] (coercion/request-coercer this :response spec {})))
(-response-coercer [this spec] (coercion/request-coercer this :response spec {}))
(-query-string-coercer [_ _]))

(comment
(doseq [coercion [nil (->NoOpCoercion) spec/coercion]]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@
request (json-request data)
request! (request-stream request)]]

"10b"
;; # 10b
;; 38µs (c-api 1.x)
;; 14µs (c-api 2.0.0-alpha21)
;; 6µs

"100b"
;; # 100b
;; 74µs (c-api 1.x)
;; 16µs (c-api 2.0.0-alpha21)
;; 8µs

"1k"
;; # 1k
;; 322µs (c-api 1.x)
;; 24µs (c-api 2.0.0-alpha21)
;; 16µs

"10k"
;; # 10k
;; 3300µs (c-api 1.x)
;; 120µs (c-api 2.0.0-alpha21)
;; 110µs

"100k"
;; # 100k
;; 10600µs (c-api 1.x)
;; 1100µs (c-api 2.0.0-alpha21)
;; 1100µs
Expand Down
24 changes: 12 additions & 12 deletions perf-test/clj/reitit/nodejs_perf_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@
(defn routing-test []

;; 21385 / 14337
"barista"
;; "barista"

;; 26259 / 25571
"choreographer"
;; "choreographer"

;; 24277 / 19174
"clutch"
;; "clutch"

;; 26158 / 25584
"connect"
;; "connect"

;; 24614 / 25413
"escort"
;; "escort"

;; 21979 / 18595
"express"
;; "express"

;; 23123 / 25405
"find-my-way"
;; "find-my-way"

;; 24798 / 25286
"http-hash"
;; "http-hash"

;; 24215 / 23670
"i40"
;; "i40"

;; 23561 / 26278
"light-router"
;; "light-router"

;; 28362 / 30056
"http-raw"
;; "http-raw"

;; 25310 / 25126
"regex"
;; "regex"

;; 112719 / 113959
(title "reitit")
Expand Down
8 changes: 4 additions & 4 deletions test/clj/reitit/http_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@
["/ping" {:get {:interceptors [{:enter #(a/go %)}]
:handler (fn [_] (a/go response))}}])
(ring/create-default-handler)
{:executor sieppari/executor})]
(let [respond (promise)]
(app {:request-method :get, :uri "/ping"} respond ::irrelevant)
(is (= response (deref respond 100 ::timeout)))))))
{:executor sieppari/executor})
respond (promise)]
(app {:request-method :get, :uri "/ping"} respond ::irrelevant)
(is (= response (deref respond 100 ::timeout))))))

(defrecord MyAsyncContext [])

Expand Down
5 changes: 1 addition & 4 deletions test/cljc/reitit/coercion_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
(:require [clojure.spec.alpha :as cs]
[clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[malli.core :as m]
[malli.experimental.lite :as l]
[reitit.coercion :as coercion]
[reitit.coercion.malli]
[reitit.coercion.schema]
[reitit.coercion.spec]
[reitit.core :as r]
[schema.core :as s]
[spec-tools.data-spec :as ds]
[malli.transform :as mt])
[spec-tools.data-spec :as ds])
#?(:clj
(:import (clojure.lang ExceptionInfo))))

Expand Down Expand Up @@ -110,7 +108,6 @@
(testing "spec-coercion (shallow)"
(testing "succeeds"
(let [m (r/match-by-path r "/spec-shallow/1/abba")]
(def MATCH m)
(is (= {:path {:keyword :abba, :number 1}, :query nil}
(coercion/coerce! m))))
(let [m (r/match-by-path r "/spec-shallow/1/abba")]
Expand Down
15 changes: 8 additions & 7 deletions test/cljc/reitit/core_test.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(ns reitit.core-test
(:require [clojure.test :refer [are deftest is testing]]
[reitit.core :as r #?@(:cljs [:refer [Router]])]
[reitit.core :as r]
[reitit.impl :as impl])
#?(:clj
(:import (clojure.lang ExceptionInfo)
(reitit.core Router))))
(:import (clojure.lang ExceptionInfo))))

(defn- var-handler [& _]
"var-handler")
Expand Down Expand Up @@ -261,10 +260,12 @@
(is (= #'var-handler result))))))

(testing "custom router"
(let [router (r/router ["/ping"] {:router (fn [_ _]
(reify Router
(r/router-name [_]
::custom)))})]
(let [router (r/router
["/ping"]
{:router (fn [_ _]
#_{:clj-kondo/ignore [:missing-protocol-method]}
(reify r/Router
(router-name [_] ::custom)))})]
(is (= ::custom (r/router-name router)))))

(testing "bide sample"
Expand Down
1 change: 0 additions & 1 deletion test/cljc/reitit/openapi_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[jsonista.core :as j]
[malli.core :as mc]
[matcher-combinators.test :refer [match?]]
[matcher-combinators.matchers :as matchers]
[muuntaja.core :as m]
[reitit.coercion.malli :as malli]
[reitit.coercion.schema :as schema]
Expand Down
6 changes: 3 additions & 3 deletions test/cljc/reitit/ring_coercion_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#?@(:clj [[muuntaja.core]
[muuntaja.middleware]
[jsonista.core :as j]
[reitit.ring.middleware.muuntaja]])
[reitit.coercion.schema :as schema]
[reitit.ring.middleware.muuntaja]
[schema.core :as s]])
[malli.core :as m]
[malli.util :as mu]
[meta-merge.core :refer [meta-merge]]
[reitit.coercion.malli :as malli]
[reitit.coercion.schema :as schema]
[reitit.coercion.spec :as spec]
[reitit.core :as r]
[reitit.ring :as ring]
[reitit.ring.spec]
[reitit.ring.coercion :as rrc]
[schema.core :as s]
[clojure.spec.alpha]
[spec-tools.data-spec :as ds])
#?(:clj
Expand Down
14 changes: 7 additions & 7 deletions test/cljc/reitit/ring_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[reitit.core :as r]
[reitit.middleware :as middleware]
[reitit.ring :as ring]
[reitit.trie :as trie])
#?(:clj [reitit.trie :as trie]
:cljs [reitit.trie :as-alias trie]))
#?(:clj
(:import (clojure.lang ExceptionInfo))))

Expand Down Expand Up @@ -847,23 +848,22 @@
(let [body (:body (app {:request-method :get, :uri (str "/" n)}))]
(is (= body (str n))))))))))))

(declare routes)
(def routes (atom nil))

(deftest reloading-ring-handler-test
(let [r (fn [body] {:status 200, :body body})]
(def routes ["/" (constantly (r "1"))]) ;; initial value

(let [create-handler (fn [] (ring/ring-handler (ring/router routes)))]
(reset! routes ["/" (constantly (r "1"))]) ;; initial value
(let [create-handler (fn [] (ring/ring-handler (ring/router @routes)))]
(testing "static ring handler does not see underlying route changes"
(let [app (create-handler)]
(is (= (r "1") (app {:uri "/", :request-method :get})))
(def routes ["/" (constantly (r "2"))]) ;; redefine
(reset! routes ["/" (constantly (r "2"))]) ;; redefine
(is (= (r "1") (app {:uri "/", :request-method :get})))))

(testing "reloading ring handler sees underlying route changes"
(let [app (ring/reloading-ring-handler create-handler)]
(is (= (r "2") (app {:uri "/", :request-method :get})))
(def routes ["/" (constantly (r "3"))]) ;; redefine again
(reset! routes ["/" (constantly (r "3"))]) ;; redefine again
(is (= (r "3") (app {:uri "/", :request-method :get}))))))))

(defrecord FooTest [a b])
Expand Down
Loading