metosin / reitit

A fast data-driven routing library for Clojure/Script
https://cljdoc.org/d/metosin/reitit/
Eclipse Public License 1.0
1.42k stars 254 forks source link

Clojure record in route data is converted to a plain map #686

Closed manderson202 closed 3 months ago

manderson202 commented 3 months ago

I have a route with some data on it where the value is a Clojure record. When I pass that route through reitit.ring/router it converts it to a regular map. This is on version 0.7.0

The source of the problem appears to be here. Perhaps a fix could be as simple as adding a condition prior to this line for record? and treating it as an opaque value without further de-structuring?

Reproducible example:

(defrecord FooTest [a b])
=> repl.FooTest

(reitit.core/match-by-path
 (reitit.ring/router
  ["/api/foo" {:get {:handler (constantly {:status 200})
                     :test (->FooTest 1 22)}}])
 "/api/foo")
=> #reitit.core.Match{:template "/api/foo", :data {:get {:handler #function[clojure.core/constantly/fn--5740], :test {:a 1, :b 22}}}, :result #reitit.ring.Methods{:get #reitit.ring.Endpoint{:data {:handler #function[clojure.core/constantly/fn--5740], :test {:a 1, :b 22}}, :handler #function[clojure.core/constantly/fn--5740], :path "/api/foo", :method :get, :middleware []}, :head nil, :post nil, :put nil, :delete nil, :connect nil, :options #reitit.ring.Endpoint{:data {:no-doc true, :handler #function[reitit.ring/fn--28003/fn--28012]}, :handler #function[reitit.ring/fn--28003/fn--28012], :path "/api/foo", :method :options, :middleware []}, :trace nil, :patch nil}, :path-params {}, :path "/api/foo"}

Note that :test in the output is a plain map and no longer a record.