Closed willspecht closed 3 years ago
Can you give some more information about the content type of the response?
"content-type": "application/json; charset=utf-8"
Can you print out the full HTTP request/response? What you've provided there doesn't look like JSON?
(ns c2.spec
(:require [compojure.api.sweet :refer [context GET POST resource]]
[ring.util.http-response :refer [ok]]
[clojure.spec.alpha :as s]
[spec-tools.spec :as spec]
[clojure.spec.gen.alpha :as gen]))
(s/def ::inst inst?)
(s/def ::inst-map (s/keys :req-un [::inst]))
(def routes
(context "/" []
:tags ["spec"]
:coercion :spec
(GET "/gen-inst" []
:summary "plus with clojure.spec"
:return ::inst-map
(ok {:inst (gen/generate (s/gen ::inst))}))
Tried to make a simple example using the c2 code example as a base.
the endpoint returns
{
"inst": "1969-12-31T23:59:59Z"
}
Above you can see how the example response has the untruncated inst value, but the response is truncated, dropping the decimal value.
Is there any additional information I can provide to help resolve this?
The solution is to set jsonista's :date-format
via Muuntaja settings – by default the date format does not include milliseconds.
Thanks for the tip. @miikka is there an example where a custom :date-format
is defined in an app that uses Compojure API?
Docs have example on setting Transit readers and writers, configuring Jsonista should be quite similar.
Muuntaja format encoder-opts
and decoder-opts
properties are used to configure Jsonista object-mapper
s.
https://cljdoc.org/d/metosin/muuntaja/0.6.7/doc/configuration https://metosin.github.io/jsonista/jsonista.core.html#var-object-mapper
Something like
(def muuntaja
(m/create
(update-in
muuntaja/default-options
[:formats "application/json"]
merge
{:encoder-opts {:date-format "..."}})))
(api
{:formats muuntaja}
...)
Since this is basically a solved issue, I'll close it.
Library Version(s) "2.0.0-alpha28"
Problem
Inst are getting truncated in response. Should be returning
{:some-field 1970-01-01T00:06:49.123Z}
But instead get{:some-field 1970-01-01T00:06:49Z}
This is causing tests to fail since I'm generating the response with spec and it doesn't match the response mocked from the route. I tried turning off coercion for the response but the truncating is still happening. Any way I can prevent this truncation from happening?
The example response in swagger looks correct as well but the actual response is truncated.