目前我正在使用 Yada 作为 web lib。现在我想在路由被命中之前执行一些功能。
我测试过的方法: - 将当前资源包装为子资源,但随后 swagger-doc 找不到资源 - 使用前置拦截器,但此时文档不完整,我遇到错误
我的代码:
(ns all-mighty.namespace
(:require [yada.yada :refer [handler listener resource as-resource]]
[yada.swagger :refer [swaggered]])
(defn resources []
[""
(swaggered
[""
[
(cool-route)
]]
{:info {:title "Hello You!"
:version "1.0"
:description "It's something"}
:basePath ""}
)])
(defn cool-route []
["/cool" (resource {
:description "Returns somethign cool"
:produces "application/json"
:methods {:get {:response cool-response}}}
)])
(defn cool-response [ctx]
(-> (:response ctx)
(assoc :status 200)
(assoc :body {:state :up}))
是的,我稍后会重构资源;-)
有人有想法吗?