This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-05
Channels
- # babashka (14)
- # beginners (62)
- # calva (1)
- # cider (54)
- # clj-kondo (3)
- # cljdoc (15)
- # cljs-dev (2)
- # clojure (180)
- # clojure-europe (5)
- # clojure-italy (4)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-spec (10)
- # clojure-uk (39)
- # clojurescript (85)
- # core-async (9)
- # core-logic (1)
- # core-typed (5)
- # data-science (27)
- # datomic (2)
- # emacs (15)
- # figwheel-main (98)
- # fulcro (26)
- # graphql (15)
- # helix (1)
- # jobs-discuss (26)
- # kaocha (1)
- # off-topic (54)
- # other-lisps (1)
- # re-frame (21)
- # reagent (1)
- # reitit (3)
- # shadow-cljs (49)
- # spacemacs (12)
- # specter (5)
- # xtdb (2)
Not sure if this is a bug or not, but I have an endpoint that takes in an XML message as the whole body. I have the following route (with coercion):
["/foo" {:swagger {:tags ["foo"]
:consumes ["application/xml"]}}
["/bar"
{:post {:parameters {:body string?}
:handler foo/bar-handler}}]]
But calling the endpoint (either via swagger or directly) throws a spec error:
$ curl -v -X POST "" -H "accept: application/json" -H "Content-Type: application/xml" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>1</foo>" | jq .
{
"spec": "(spec-tools.core/spec {:spec clojure.core/string?, :type :string, :leaf? true})",
"problems": [
{
"path": [],
"pred": "clojure.core/string?",
"val": null,
"via": [],
"in": []
}
],
"type": "reitit.coercion/request-coercion",
"coercion": "spec",
"value": null,
"in": [
"request",
"body-params"
]
}
Using some?
or identity
instead of string?
also fail.
Swagger shows correctly that this endpoint consumes XML though, with a nice empty XML template where you can fill in the body.@tanel.kriik if you don’t have a middleware that reads the XML into :body-params
that doesn’t work, as the params are nil
. You can add the swagger parameter manually into endpoint with something like : :swagger {:parameters [{:in :body, :name "xml", :required true, :schema {}]]}
and say (slurp (:body request))
to read the xml-string in your handler.