Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Immutable `restructure` interface

未关闭
#468 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
clojure
领域
api, backend

调研方向

从提议的 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

metosin/compojure-api 的其他 Issue

查看 metosin/compojure-api 的全部 Issue

相似的 Issue

更多 Clojure Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。