reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
timo 2020-11-20T16:11:33.353100Z

Hi! I wonder why I am getting namespaced parameters when using spec for coercion in reitit. Any ideas on how to use unqualified here?

timo 2020-11-20T16:13:05.353700Z

(s/def ::entity any?)
(s/def ::tx-data (s/coll-of ::entity))
(s/def ::tx-meta (s/coll-of ::entity))
(s/def ::transactions (s/keys :req-un [::tx-data] :opt-un [::tx-meta]))

Dave Russell 2020-11-21T13:52:11.354200Z

Swagger generation depends on your coercion, and in the case of spec it will coerce your parameters into swagger docs https://github.com/metosin/reitit/blob/master/modules/reitit-spec/src/reitit/coercion/spec.cljc#L97, and will use spec-tools to do it 🙂

Dave Russell 2020-11-21T13:52:48.354500Z

So try wrapping your spec definition with an https://github.com/metosin/spec-tools/blob/master/docs/05_swagger.md#annotated-specs

Dave Russell 2020-11-21T13:54:51.354800Z

So you'd declare your body params with something like:

["/transact" {:post {:parameters {:body (st/spec {:spec ::transactions
                                                  :name "Transactions"})}}}]

Dave Russell 2020-11-21T13:57:17.355400Z

Maybe that will work? 🙂

timo 2020-11-22T14:34:03.355600Z

Thanks @david.russell. That did actually work!

👍 1
neotyk 2020-11-20T16:22:01.353800Z

Try:

(s/def :entity any?)
(s/def ::tx-data (s/coll-of :entity))

timo 2020-11-20T16:28:20.354Z

well. the entity bit is more a placeholder here. That needs to be further specced. but reitit does not allow non-namespaced keywords.

Assert failed: k must be namespaced keyword or resolvable symbol
(c/and (ident? k) (namespace k))