reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
matheusashton 2021-05-12T15:39:11.250600Z

I'm still trapped in how to coerce a string datetime in iso format to a java.util.Date or something similar, in my requests with reitit and ring, can somebody help please? 😢

matheusashton 2021-05-14T17:29:56.258600Z

my problem isn't exactly the conversion per se, but how to use it with coerce request middleware

matheusashton 2021-05-14T17:31:38.258800Z

because it is already coercing the request to basic data, but I don't know how to make it recognize that a json field is a date and use some function to coerce it

matheusashton 2021-05-12T15:43:22.253500Z

tried to follow how reitit works internally in reitit.ring.coercion.coerce-request-middleware with reitit.coercion.schema but couldn't understand how reitit get the matchers in order to call schema.coerce.coercer , I think I can just use schema-tools.coerce/json-coercion-matcher that will work, in the coercer call, but I don't know how to configure this in the middleware exaclty

dharrigan 2021-05-12T15:46:00.253900Z

I have this, although I'm using malli...

dharrigan 2021-05-12T15:46:09.254100Z

;; ISO_OFFSET_DATE_TIME format, e.g., 2011-12-03T10:15:30+01:00 or 2011-12-03T10:15:30Z
(defn ^:private date-time-parser
  [date-time]
  (try
   (.parse DateTimeFormatter/ISO_OFFSET_DATE_TIME date-time)
   (catch DateTimeParseException _
     nil)))

dharrigan 2021-05-12T15:46:17.254300Z

(def date-range [:map
                 {:closed true}
                 [:from {:optional true} [:fn {:swagger/type "string" :swagger/format "date-time" :error/message iso8601-message} date-time-parser]]
                 [:to {:optional true} [:fn {:swagger/type "string" :swagger/format "date-time" :error/message iso8601-message} date-time-parser]]])

dharrigan 2021-05-12T15:46:22.254500Z

maybe that might help?

dharrigan 2021-05-12T15:48:19.255300Z

(def ^:private iso8601-message "is not in ISO DATE TIME format, e.g. 2020-07-03T10:15:30+01:00 or 2020-07-03T10:15:30Z")

matheusashton 2021-05-12T15:48:59.255800Z

hmm where do you use date-range?

dharrigan 2021-05-12T15:49:20.256Z

In my posts

dharrigan 2021-05-12T15:49:35.256300Z

for example:

dharrigan 2021-05-12T15:50:11.257200Z

(def start (mu/merge data-range) [:map {:closed true} [:name string?]}))

dharrigan 2021-05-12T15:50:47.257500Z

:post {:handler (start app-config)
               :parameters {:body specs/start}
               :swagger {:produces [blah-blah-version]}}}]

matheusashton 2021-05-12T15:52:22.258Z

I'll try to check how malli works to see if I can adapt this to schema

2021-05-12T15:56:15.258300Z

you could try functions from the core - https://clojuredocs.org/clojure.instant