This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-29
Channels
- # aleph (4)
- # architecture (12)
- # bangalore-clj (1)
- # beginners (87)
- # boot (3)
- # cider (19)
- # cljs-dev (84)
- # clojars (10)
- # clojure (79)
- # clojure-italy (7)
- # clojure-nl (19)
- # clojure-russia (10)
- # clojure-spec (9)
- # clojure-uk (55)
- # clojurescript (64)
- # core-async (7)
- # core-typed (4)
- # cursive (7)
- # data-science (2)
- # datomic (8)
- # devcards (6)
- # docs (1)
- # duct (5)
- # fulcro (117)
- # graphql (1)
- # instaparse (1)
- # leiningen (13)
- # lumo (103)
- # nyc (3)
- # off-topic (54)
- # om (9)
- # onyx (1)
- # pedestal (6)
- # planck (3)
- # portkey (7)
- # re-frame (26)
- # reagent (20)
- # ring-swagger (14)
- # shadow-cljs (164)
- # sql (11)
- # tools-deps (25)
- # yada (1)
Whats the best way to coerce dates with compojure-api 2.0 and spec?
… but mostly the spec wrapping is done automatically, so this should work too:
:body-params [date :- inst?]
would it work with “yyyy-MM-dd” as well? or only full ISO date format?
here are the tests: https://github.com/metosin/spec-tools/blob/master/test/cljc/spec_tools/transform_test.cljc#L37-L44
thanks a lot!
[date :- inst?]
would display date-time
data type in swagger ui, what if i want date
type(2018-05-20 format), not the date-time one, with spec
currently, there are no other date-style specs available, but you can create those yourself. something like:
(require '[spec-tools.core :as st])
(def date?
(st/spec
{:spec inst?
:json-schema/format "date"}))
(date? (java.util.Date.))
;; true
(st/decode date? "2018-05-20" st/json-transformer)
; #inst"2018-05-20T00:00:00.000-00:00"
(require '[spec-tools.swagger.core :as swagger])
(swagger/transform date?)
; {:type "string", :format "date"}
if you want it to be LocalDate
, just change the predicate and create custom decode
function.