Immutable `restructure` interface
还没有人认领这个 Issue。
评估
调研方向
从提议的 create-compojure-api 宏及其生成的 GET、ANY、PATCH、DELETE、POST、PUT、context、routes、middleware 和 undocumented 入口点开始。检查不可变 options map 如何传递给这些宏,以及如何选择 restructure 扩展。完成的标准是:不可变且受限的配置能够生成预期的 API,而不依赖大型的可扩展 restructure 多方法。
由索引模型根据 Issue 内容生成。
描述
Instead of a big restructure multimethod that you need to manage extensions for, perhaps we can encourage more mix-and-match approaches that start to look like the kind of centralized config you'd expect from reitit.
One of the motivations is having full control and certainty over the restructure options for security purposes.
Since compojure-api is macro-based, the main obstacle here is forwarding the immutable config to the macros. This can be accomplished by a macro-generating macro.
e.g.,
(ns my-bare-bones-compojure-api
"A version of compojure-api that only supports :tags."
(:require [compojure.api.immutable :as im]
[compojure.api.meta.tags]
[clojure.set :as set]))
(def ^:private options
{:restructure {:tags compojure.api.meta.tags/extension}})
(im/create-compojure-api `options)
=>
(defmacro create-compojure-api [options]
(assert (and (seq? options)
(= 2 (count options))
(= 'quote (first options))
(qualified-symbol? (second options)))
"Options must be a quoted qualified symbol whose var contains your configuration, like: (load-api `options)")
`(let [options# ~options]
(defmacro ~'GET {:style/indent 2 :arglists '([& ~'args])} [& args#] (GET options# args#))
(defmacro ~'ANY {:style/indent 2 :arglists '([& ~'args])} [& args#] (ANY options# args#))
(defmacro ~'PATCH {:style/indent 2 :arglists '([& ~'args])} [& args#] (PATCH options# args#))
(defmacro ~'DELETE {:style/indent 2 :arglists '([& ~'args])} [& args#] (DELETE options# args#))
(defmacro ~'POST {:style/indent 2 :arglists '([& ~'args])} [& args#] (POST options# args#))
(defmacro ~'PUT {:style/indent 2 :arglists '([& ~'args])} [& args#] (PUT options# args#))
(defmacro ~'context
"Like compojure.api.core/context, except the binding vector must be empty and
no binding-style options are allowed. This is to prevent the passed routes
from being reinitialized on every request."
{:style/indent 2 :arglists '~'([path arg & args])}
[path# arg# & args#]
(context options# path# arg# args#))
(defn ~'routes
"Create a Ring handler by combining several handlers into one."
{:style/indent 2 :arglists '~'([& handlers])}
[& handlers#]
(routes options# handlers#))
(defmacro ~'middleware
"Wraps routes with given middlewares using thread-first macro.
Note that middlewares will be executed even if routes in body
do not match the request uri. Be careful with middlewares that
have side-effects."
{:style/indent 1 :arglists '~'([middleware & body-exprs])}
[middleware# & body-exprs#]
(middleware options# middleware# body-exprs#))
(defmacro ~'undocumented
"Routes without route-documentation. Can be used to wrap routes,
not satisfying compojure.api.routes/Routing -protocol."
{:arglists '~'([& handlers])}
[& handlers#]
(undocumented options# handlers#))))
- 主要语言
- Clojure
- 星标
- 1.1k
- 派生
- 145
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
metosin/compojure-api 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
metosin/compojure-api#489 ·
-
难度 5/5 一周以上 新手友好度 20/100
metosin/compojure-api#467 ·
-
难度 5/5 一周以上 新手友好度 25/100
metosin/compojure-api#464 ·
-
难度 5/5 一周以上 新手友好度 30/100
metosin/compojure-api#463 · 3 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
metosin/compojure-api#462 · 3 条评论 ·
查看 metosin/compojure-api 的全部 Issue
相似的 Issue
-
Permissioned transactions fetch each entity once per tx-step, producing huge permission-check queries可能已有人在做 @verveguy 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 84/100
clojure-lsp/clojure-lsp#2502 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复