Internal functions used by metabase.api.common
.
These are primarily used as the internal implementation of defendpoint
.
Internal functions used by `metabase.api.common`. These are primarily used as the internal implementation of `defendpoint`.
Map of param-type
-> map with the following keys:
:route-param-regex Regex pattern that should be used for params in Compojure route forms :parser Function that should be used to parse args
Map of `param-type` -> map with the following keys: :route-param-regex Regex pattern that should be used for params in Compojure route forms :parser Function that should be used to parse args
(arg-type arg)
Return a key into *auto-parse-types*
if ARG has a matching pattern in auto-parse-arg-name-patterns
.
(arg-type :id) -> :int
Return a key into `*auto-parse-types*` if ARG has a matching pattern in `auto-parse-arg-name-patterns`. (arg-type :id) -> :int
(auto-parse args & body)
Create a let
form that applies corresponding parse-fn for any symbols in ARGS that are present in
*auto-parse-types*
.
Create a `let` form that applies corresponding parse-fn for any symbols in ARGS that are present in `*auto-parse-types*`.
(let-form-for-arg arg-symbol)
Given an ARG-SYMBOL like id
, return a pair like [id (Integer/parseInt id)]
that can be used in a let
form.
Given an ARG-SYMBOL like `id`, return a pair like `[id (Integer/parseInt id)]` that can be used in a `let` form.
(parse-int value)
Parse VALUE (presumabily a string) as an Integer, or throw a 400 exception. Used to automatically to parse id
parameters in defendpoint
functions.
Parse VALUE (presumabily a string) as an Integer, or throw a 400 exception. Used to automatically to parse `id` parameters in `defendpoint` functions.
(route-arg-keywords route)
Return a sequence of keywords for URL args in string ROUTE.
(route-arg-keywords "/:id/cards") -> [:id]
Return a sequence of keywords for URL args in string ROUTE. (route-arg-keywords "/:id/cards") -> [:id]
(route-dox method route docstr args param->schema body)
Generate a documentation string for a defendpoint
route.
Generate a documentation string for a `defendpoint` route.
(route-fn-name method route)
Generate a symbol suitable for use as the name of an API endpoint fn. Name is just METHOD + ROUTE with slashes replaced by underscores.
(route-fn-name GET "/:id") ;-> GET_:id
Generate a symbol suitable for use as the name of an API endpoint fn. Name is just METHOD + ROUTE with slashes replaced by underscores. (route-fn-name GET "/:id") ;-> GET_:id
(route-param-regex arg)
If keyword ARG has a matching type, return a pair like [arg route-param-regex]
,where ROUTE-PARAM-REGEX is the
regex that this param that arg must match.
(route-param-regex :id) -> [:id #"[0-9]+"]
If keyword ARG has a matching type, return a pair like `[arg route-param-regex]`,where ROUTE-PARAM-REGEX is the regex that this param that arg must match. (route-param-regex :id) -> [:id #"[0-9]+"]
(typify-args args)
Given a sequence of keyword ARGS, return a sequence of [:arg pattern :arg pattern ...]
for args that have
matching types.
Given a sequence of keyword ARGS, return a sequence of `[:arg pattern :arg pattern ...]` for args that have matching types.
(typify-route route)
Expand a ROUTE string like "/:id" into a Compojure route form that uses regexes to match parameters whose name
matches a regex from auto-parse-arg-name-patterns
.
(typify-route "/:id/card") -> ["/:id/card" :id #"[0-9]+"]
Expand a ROUTE string like "/:id" into a Compojure route form that uses regexes to match parameters whose name matches a regex from `auto-parse-arg-name-patterns`. (typify-route "/:id/card") -> ["/:id/card" :id #"[0-9]+"]
(validate-param field-name value schema)
Validate a parameter against its respective schema, or throw an Exception.
Validate a parameter against its respective schema, or throw an Exception.
(validate-params param->schema)
Generate a series of validate-param
calls for each param and schema pair in PARAM->SCHEMA.
Generate a series of `validate-param` calls for each param and schema pair in PARAM->SCHEMA.
(wrap-response-if-needed response)
If RESPONSE isn't already a map with keys :status
and :body
, wrap it in one (using status 200).
If RESPONSE isn't already a map with keys `:status` and `:body`, wrap it in one (using status 200).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close