ring-swagger & compojure-api
mgrbyte 2019-03-13T14:47:02.004400Z

If my compojure-api API gives a 500 with a path containing spaces e.g /api/foo/some id with spaces, is that a bug in the library or something I've not done as a developer? (perhaps added some ring middleware?)

ikitommi 2019-03-13T15:26:00.007Z

@mgrbyte good question, haven't seen that. Could you test that with plain Compojure? 500 sounds odd thou.

mgrbyte 2019-03-13T15:28:10.009100Z

Just tracked it down. Have a custom error handler which tries to turn spec errors into an error message with bad-request. spec validation error couldn't be written to stream, so answered my own question.

mgrbyte 2019-03-13T15:28:24.009300Z


mgrbyte 2019-03-13T15:47:48.011300Z

tracked down exactly the cause. My error handler uses a small function to encode the response:

(defn respond-with [response-fn request data]
  (let [fmt (-> request
    (-> data
        (content-type fmt))))
For some reason, :default-format in this case, is nil, causing the 500 error (cannot write persistentarraymap). It works in most other cases :thinking_face:

mgrbyte 2019-03-13T15:52:33.011600Z

In fact, (:compojure.api.request/muuntaja request) is nil.

mgrbyte 2019-03-13T16:12:44.013800Z

@ikitommi I see from compojure-api's path-for* function that this might happen - I'm guessing there are cases where the muuntaja instance might not present in the request, and one has define another default? https://github.com/metosin/compojure-api/blob/5aee5b40a8477bb37557f624237395e573bf0a12/src/compojure/api/routes.clj#L229