Fork me on GitHub
#reitit
<
2020-11-20
>
timo16:11:33

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

timo16:11:05

(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]))

neotyk16:11:01

Try:

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

timo16:11:20

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))

Dave Russell13:11:11

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 Russell13:11:51

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

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

Dave Russell13:11:17

Maybe that will work? 🙂

timo14:11:03

Thanks @U01BP1CB37B. That did actually work!

👍 3