@ikitommi Planning on adding XML support for the format negotation. Anything I need to think about in order to accept a PR?
For muuntaja. Forgot to mention that
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.
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
@joefromct the extra keys are stripped away by default.
hmm... i need to fail on extra keys in this scenario
you need to change the transformers via coercion options not to do stripping of extra keys and then use closed specs.
ok, but not in the middleware chain, rather the :coercion key in reitit (i think)
@emil0r would be awesome. It should be muuntaja-xml
module, so it’s not enabled by default, like msgpack
and yaml
are.
@ikitommi PR sent
yes, something like this into route data:
:coercion (reitit.coercion.spec/create {...transformers-without-stripping...})
and then wrap with spell to close the specs.
ok thank you very much. let me take another shot at that.
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
let’s thread this.
@emil0r are you thinking the encoding/decoding would be handle by clojure.data.xml
or something else?
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
data.xml
easy to close schemas, strip-extra-keys
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
PR welcome to port those to spec-coercion too
PR is here if you’re interested https://github.com/metosin/muuntaja/pull/114
Well… it’s a bit difficult to navigate without XPath
But clojure.data.xml is well supported, which is what I think I’d want
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
Ah right… yeah, that would probably not work that well. Looks like you miss some parts of XML
yeah i'm sure... it gets tricky. safe bet is surely data.xml.