Fork me on GitHub
#reitit
<
2019-10-05
>
ikitommi06:10:14

@jake142 the response coercion only validates if there is a response model defined. It *should* strip away extra keys from both inputs & outputs, but looking at the code, it does it only for application/json, so for transit & edn, the extra keys get validated - this is a feature of clojure.spec, does it proudly, by design.

telekid16:10:07

Interesting - I think I’ll need to play around with this a bit more to really get it. I do feel that transit, edn & JSON should all behave the same way, just for clarity’s sake.

telekid16:10:51

All of our responses are application/json, but when I was playing with this on Friday I could have sworn that extra keys were being validated. If I have time later this week, I may try to make a minimal test case to gain a bit of clarity.

telekid16:10:39

Thanks for being so responsive, BTW. It makes it a lot easier to trust a fairly complex tool like reitit when the maintainer is accessible 🙏

ikitommi17:10:34

> actually, for responses, I would say the default of no-op-transformer is ok - user should ensure that responses are ok. for request, it should definetely strip.

ikitommi17:10:56

for responses, they are currently validated.

ikitommi17:10:32

only way not to validate those would be to strip away the extra keys from responses, currently not happening.

ikitommi17:10:35

.. or to convince spec core team the validating extra (qualified) keys is not right.

telekid17:10:36

> .. or to convince spec core team the validating extra (qualified) keys is not right. ooooh, now I understand what you’re getting at:

(s/def ::a string?)
(s/def ::b string?)

(s/def ::m (s/keys :req [::a]))

(s/explain ::m {::a "jake"
                ::b 20})

-- Spec failed --------------------

  {:com.flexport.capital.util.auto-fk/a ...,
   :com.flexport.capital.util.auto-fk/b 10}
                                        ^^

should satisfy

  string?

-- Relevant specs -------

:com.flexport.capital.util.auto-fk/b:
  clojure.core/string?
:com.flexport.capital.util.auto-fk/m:
  (clojure.spec.alpha/keys :req [:com.flexport.capital.util.auto-fk/a])

-------------------------
Detected 1 error

I had no idea that spec did this. That’s fascinating. It makes sense - seems like a great idea. Just surprising.

ikitommi06:10:45

I think we should strip extra keys out by default for all formats. what do you think?

ikitommi06:10:52

the default should be st/strip-extra-keys-transformer, not no-op-transformer. PR welcome.

ikitommi06:10:40

actually, for responses, I would say the default of no-op-transformer is ok - user should ensure that responses are ok. for request, it should definetely strip.