Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Immutable `restructure` interface

Aperta
#468 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
clojure
Ambito
api, backend

Direzione di ricerca

Inizia con la macro create-compojure-api proposta e i suoi punti di ingresso generati GET, ANY, PATCH, DELETE, POST, PUT, context, routes, middleware e undocumented. Esamina come la mappa di opzioni immutabile viene inoltrata a queste macro e come vengono selezionate le estensioni di restructure. Il lavoro è completato quando una configurazione immutabile e limitata può generare l’API prevista senza dipendere dal grande multimethod estensibile di restructure.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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#))))
Lingua principale
Clojure
Stelle
1.1k
Fork
145
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di metosin/compojure-api

Tutte le issue di metosin/compojure-api

Issue simili

Altre issue su Clojure

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.