Pass full options down to content handlers #54
Conversation
Previously, the top-level options of content handlers (e.g. decoder, predicate) could not be overriden from the outside caller. With these changes this gets fixed. Options to the decoder inside the handlers need to be passed as `:decoder-options` now.
fixes #55 |
Is there a reason to break API by changing the name of option? I want to keep the API as stable as possible. |
Hmm, I see now why the name change. This will need some consideration. I want to either keep current API working or add a compile time error if user is using old options. |
Also, if the change is done, it would be nice to change |
tbh I cannot see anymore, why I thought the name HAS to be changed. Do you mind explaining, why it needs to be renamed? Is there any conflict somewhere? Good point about the response handlers, will look into that. |
Well I guess it strictly doesn't need to be changed as format specific middlewares The really breaking change is that restful middleware |
One option would be to leave restful middleware Unlike Compojure-api, we are not using macros so I don't think it's possible to do compile time option validation. I guess runtime validation would be nearly as good as middlewares are initialized when starting the app. But then, I'm not sure how to differentiate old and new format-options values for validation. |
@Deraen I had a look at the response side of things. Creating the writers and handling options is a bit different there. What I ended up with now, is just passing a new option (wrap-restful-format :formats [:transit-json :json-kw]
:response-options {:transit-json {:writer-fn (fn [out _ options] (om/writer out options))}}) Being picked up in (defn ^:no-doc make-transit-encoder
[fmt {:keys [verbose writer-fn] :as options}]
(fn [data]
(let [out (ByteArrayOutputStream.)
full-fmt (if (and (= fmt :json) verbose)
:json-verbose
fmt)
wrt ((or writer-fn transit/writer) out full-fmt options)]
(transit/write wrt data)
(.toByteArray out)))) The same would be possible on the As you can see, I want to use the transit writer provided by om.next and I can do so with this approach. So at least for my use case, this would be sufficient and not be a breaking API change. However, the options passing is still broken or at least misleading with respect to replacing What do you think? |
Is transit writer okay with additional options? I guess the Is there real use case for setting per type options? I think it usually makes sense to use the same predicate option for all formats and I don't know when binary option would need to be changed. I consider this library to be mostly complete and in maintenance mode. I plan on building a new library in future which would fix mostly the implementation problems with this library, allow easier extending and fix some problems with the API (options). |
On comment about the example: Move |
@nblumoe I don't don't have plans for new releases breaking the current API or adding new features, so in this case I'd say this PR is not going to be merged. |
Previously, the top-level options of content handlers (e.g. decoder,
predicate) could not be overriden from the outside caller. With these
changes this gets fixed.
Options to the decoder inside the handlers need to be passed as
:decoder-options
now.