reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
emil0r 2020-05-06T08:12:06.320700Z

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

emil0r 2020-05-06T08:52:28.321Z

For muuntaja. Forgot to mention that

joefromct 2020-05-06T14:06:49.325500Z

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.

joefromct 2020-05-06T14:17:24.327Z

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

ikitommi 2020-05-06T14:25:01.327600Z

@joefromct the extra keys are stripped away by default.

joefromct 2020-05-06T14:25:27.328400Z

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

ikitommi 2020-05-06T14:26:07.329700Z

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

joefromct 2020-05-06T14:27:05.331300Z

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

ikitommi 2020-05-06T14:27:21.331700Z

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

emil0r 2020-05-06T14:28:18.333400Z

@ikitommi PR sent

ikitommi 2020-05-06T14:28:46.334200Z

yes, something like this into route data:

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

ikitommi 2020-05-06T14:29:00.334500Z

and then wrap with spell to close the specs.

joefromct 2020-05-06T14:29:19.335100Z

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

emil0r 2020-05-06T14:29:22.335300Z

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

ikitommi 2020-05-06T14:29:41.335700Z

let’s thread this.

joefromct 2020-05-06T14:29:58.336100Z

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

ikitommi 2020-05-06T14:30:02.336200Z

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

emil0r 2020-05-06T14:30:09.336700Z

data.xml

ikitommi 2020-05-06T14:30:28.337100Z

easy to close schemas, strip-extra-keys

joefromct 2020-05-06T14:30:40.337700Z

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

ikitommi 2020-05-06T14:30:45.337800Z

PR welcome to port those to spec-coercion too

emil0r 2020-05-06T14:30:45.338Z

PR is here if you’re interested https://github.com/metosin/muuntaja/pull/114

emil0r 2020-05-06T14:31:08.338400Z

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

emil0r 2020-05-06T14:31:42.339100Z

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

joefromct 2020-05-06T14:32:58.340Z

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

emil0r 2020-05-06T14:35:46.341Z

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

joefromct 2020-05-06T14:36:12.341400Z

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