Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Indent test
(defmethod restructure-param :path-params
[_ {:keys [lets letks parameters] :as acc}]
"restructures path-params by plumbing letk notation. generates
synthetic defs for the models. example:
:path-params [id :- long name :- string]"
(if-let [path-params (:path-params parameters)]
(let [schema (fnk-schema path-params)
model-name (gensym "path-params-")
_ (eval `(def ~model-name ~schema))
coerced-model (gensym)]
(assoc acc
:lets (into lets [coerced-model `(schema/coerce!
(:route-params ~+compojure-api-request+)
:parameters (-> parameters
(dissoc :path-params)
(update-in [:parameters] conj
{:type :path
:model (eval `(var ~model-name))}))
:letks (into letks [path-params coerced-model])))))
(defn- destructure-compojure-api-request [lets arg]
(vector? arg) [lets (into arg [:as +compojure-api-request+])]
(map? arg) (if-let [as (:as arg)]
[(conj lets +compojure-api-request+ as) arg]
[lets (merge arg [:as +compojure-api-request+])])
(symbol? arg) [(conj lets +compojure-api-request+ arg) arg]
:else (throw
(str "unknown compojure destruction synxax: " arg)))))
;; Vim settings:
;; let g:clojure_fuzzy_indent_patterns=['^GET', '^POST', '^PUT', '^DELETË́', '^ANY', '^HEAD', '^PATCH', '^OPTIONS']
;; autocmd FileType clojure setlocal lispwords+=describe,it,testing,facts,fact,provided
(GET* "/echo" []
:return QueryParams
:query [query QueryParams]
(ok query))
"/echo" []
:return QueryParams
:query [query QueryParams]
(ok query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment