Fork me on GitHub
#reitit
<
2020-05-06
>
emil0r08:05:06

@ikitommi Planning on adding XML support for the format negotation. Anything I need to think about in order to accept a PR?

emil0r08:05:28

For muuntaja. Forgot to mention that

joefromct14:05:49

Hi, does anyone have any idea why a closed spec might not throw a 400 when given extra keys? Maybe i mis-understood the documents, but i followed the 'close spec validation' page at Route Data Validation pretty closely and am still not getting a http 200 with extraneous keys. (For a swagger end point on a system border). I thought it was simple as this: https://github.com/joefromct/close-spec-test/blob/master/src/clj/close_spec_test/handler.clj#L70-L74 But this test still fails; it returns an unexpected 200: https://github.com/joefromct/close-spec-test/blob/master/test/clj/close_spec_test/test/handler_test.clj#L31-L33 I must be missing something... any tips appreciated.

joefromct14:05:24

I guess i'm unclear on if i declare a spec closed on the :validation, or :spec keys, or :rs/wrap, or do i need to declare the spec with (spell/closed), or if it actually needs assertions in the function matched by the router. or maybe its ideal to do it in a string transformer with spec tools, although i think that would be applied at coercion time, so maybe it needs something with the :coerce key in a route

ikitommi14:05:01

@joefromct the extra keys are stripped away by default.

joefromct14:05:27

hmm... i need to fail on extra keys in this scenario

ikitommi14:05:07

you need to change the transformers via coercion options not to do stripping of extra keys and then use closed specs.

joefromct14:05:05

ok, but not in the middleware chain, rather the :coercion key in reitit (i think)

ikitommi14:05:21

@emil0r would be awesome. It should be muuntaja-xml module, so it’s not enabled by default, like msgpack and yaml are.

ikitommi14:05:46

yes, something like this into route data:

:coercion (reitit.coercion.spec/create {...transformers-without-stripping...})

ikitommi14:05:00

and then wrap with spell to close the specs.

joefromct14:05:19

ok thank you very much. let me take another shot at that.

ikitommi14:05:41

let’s thread this.

ikitommi14:05:02

there could be more options to make it easier, here’s an example from malli-coercion: https://github.com/metosin/reitit/blob/master/modules/reitit-malli/src/reitit/coercion/malli.cljc#L105-L119

ikitommi14:05:28

easy to close schemas, strip-extra-keys

ikitommi14:05:45

PR welcome to port those to spec-coercion too

emil0r14:05:22

It works with my project that uses reitit for requests, the response blows up when I’ve tried to send out a response as XML

joefromct14:05:58

@emil0r are you thinking the encoding/decoding would be handle by clojure.data.xml or something else?

joefromct14:05:40

sounds good. I found it was really not json-like at all... so i actually did something else for xml... probably not feasible for the masses but fit my needs

emil0r14:05:08

Well… it’s a bit difficult to navigate without XPath

emil0r14:05:42

But clojure.data.xml is well supported, which is what I think I’d want

joefromct14:05:58

I had been using https://github.com/joefromct/clj-xmltojson/blob/master/README.org as i was trying to port software from python using https://github.com/martinblech/xmltodict but im' sure it's not performant enough for the masses

emil0r14:05:46

Ah right… yeah, that would probably not work that well. Looks like you miss some parts of XML

joefromct14:05:12

yeah i'm sure... it gets tricky. safe bet is surely data.xml.