Immutable `restructure` interface
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 30/100
調査の方向性
提案されている create-compojure-api マクロと、それによって生成される GET、ANY、PATCH、DELETE、POST、PUT、context、routes、middleware、undocumented の各エントリポイントから始めます。不変の options マップがこれらのマクロにどのように渡されるか、また restructure 拡張がどのように選択されるかを確認します。不変で制限された構成から、大規模で拡張可能な restructure マルチメソッドに依存せず、意図した API を生成できれば完了です。
索引モデルが 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 ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
metosin/compojure-api のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
metosin/compojure-api#489 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
metosin/compojure-api#467 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
metosin/compojure-api#464 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
metosin/compojure-api#463 · コメント 3 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
metosin/compojure-api#462 · コメント 3 件 ·
metosin/compojure-api の issue をすべて見る
似ている issue
-
難易度 2/5 半日 初心者へのやさしさ 84/100
clojure-lsp/clojure-lsp#2502 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信