liberator icon indicating copy to clipboard operation
liberator copied to clipboard

Disable passing response options

Open yayitswei opened this issue 6 years ago • 1 comments

Hi, thanks so much for making liberator.

It seems some behavior has changed since I last updated liberator and broke some of my endpoints. A resource that previously returned a JSON response with a key named status now incorrectly puts that value into the status code. As this is a large system with other dependencies, it's infeasible to change the response keys, for example, renaming the key from status to page-status. Can you advise on a way to keep the status key in the response in this new version of liberator, perhaps disabling the new behavior?

I believe it could be this update in 0.13 that broke the functionality I've been relying on:

New in 0.13

- Optionally a value can be specified for ring-response together with a ring map. This value is coerced to a response like liberator does by default while the ring map makes it possible to override whatever part of the response.

yayitswei avatar Feb 09 '19 10:02 yayitswei

Here's an example:

(ns liberatortest.core
  (:use [liberator.core :only [defresource]]
        [ring.mock.request :only [request header]]
        [liberator.dev]))

(defresource hello-world
  :available-media-types ["application/json"]
  :malformed? [true {:status :testing}]
  :handle-ok "ok")

liberator 0.12.2 would put {:status :testing} in response body. liberator 0.15.2 overrides the :status field, resulting in:

{:status :testing, :headers {"Content-Type" "text/plain;charset=UTF-8"}, :body "Bad request."}

yayitswei avatar Feb 09 '19 16:02 yayitswei