                  (filter symbol-for-function? (map second (ns-publics namespace)))))
     DEFAULT-MAPPINGS))
 
-;(defn- scan-namespace
-;  "Build a seq of routes for namespace by adding custom routes (for fns with :path-spec metadata) to DEFAULT_MAPPINGS"
-;  [namespace]
-;  (let [paths (ns-paths namespace)]
-;    (l/infof "Setting route mappings for %s to %s" namespace (l/pprint-str paths))
-;    (remove nil?
-;            (map #(make-function-route namespace auths env service services %) (ns-paths namespace)))))
-
-;cache seems unnecessary as we build the list once per handler
-;(def scan-namespace (memo/memo scan-namespace-uncached))
-
 (defn get-function-meta
   "Get meta for route-mapping and namespace."
   [namespace [path-spec function-key]]

    (when (symbol-for-function? f) ;it has to be a function all right
      f)))

;(defn- ns-validation
;  "Return the validation for the given namespance and action keyword (:create, :update).
;   Disables :required validations for :update actions"
;  [namespace action]
;  (when-let [v (ns-resolve namespace (symbol "validation"))]
;    (condp = action
;      :create (deref v)
;      :update (walk/postwalk-replace {[:required true] [:required false]} (deref v)))))

;(defn route-function-wrapper
;  [processors arg-resolvers namespace f]
;  (fn [request]
;    (if-let [processor (first processors)]
;      ((mw namespace (meta f) (processors-wrapper (rest processors) arg-resolvers namespace f))
;        request)
;      (invoke-handler-function f (-> f meta :arglists first)  request))))

;(defn create-function-route-handler
;  "Create a handler for a route which invokes function <f> after parsing and validation of request data (if :validate? metadata is true)
;   The function is invoked with arguments as determined by extract-param-value.
;   The request is augmented with an :env entry containing a map of :mode, :service and :services."
;  [namespace f default-middlewares default-arg-resolvers]
;  (let [{:keys [middlewares arg-resolvers arglists] :as meta-data} (meta f)]
;    (fn [request]
;      (let [request (assoc request
;                      :rook {:namespace namespace
;                             :function f
;                             :metadata meta-data
;                             :arg-resolvers (concat default-arg-resolvers arg-resolvers)})
;            rook-wrapper (route-function-wrapper (concat default-middlewares middlewares))]
;        (rook-wrapper request)))))

;    (fn [request]
;      (l/debugf "Request %s: %s" (:request-method request) (:uri request))
;          (v/validate-and-process request validation
                                  ; Add data (transformed and validated) as another option for params
;                                  (partial invoke-handler-function f (first arglists) request))
;          (invoke-handler-function f (first arglists) request nil))))))

(defn- success?
  [{:keys [status]}]
  (<= 200 status 399))

;(defn wrap-auth
;  "Ring middleware which authorizes the request by calling <auth-fn> with the request and <permissions> (a collections of permission strings or a function of the request, returning same)
;    * <handler> is called if auth is successful (auth-fn returns a 2xx status response)
;    * Otherwise the response from the auth-fn is returned as-is
;   If <auth-fn> is nil then handler is always invoked."
;  [handler auth-fn permissions]
;  (fn [request]
;    (if auth-fn
;      (let [permissions (if (fn? permissions) (permissions request) permissions)
;            auth-response (auth-fn request permissions)]
;        (if (success? auth-response)
;          (handler request)
;          auth-response))
;      (handler request))))

;(defn make-function-route
;  "Create function route from route-mapping and namespace."
;  [namespace [path-spec function-key] default-processors default-arg-resolvers]
;  (when-let [f (ns-function namespace function-key)]
;    (let [[method path] path-spec
;;          permissions (:permissions (meta f))
;;          auth (or (:auth (meta f)) :default)
;;          auth-fn (get auths auth)
;          handler (create-function-route-handler namespace f default-processors default-arg-resolvers)]
;;      (l/infof "Building route for %s with %s" [path-spec function-key] (l/pprint-str (select-keys (meta f) [:auth :permissions :path-spec :name])))
;      (compojure/make-route method path
;;                                 (wrap-auth handler auth-fn permissions)
;                                 handler
;                                 ))))


(defn function-entry
  "Create function entry if it has :path-spec defined in its metadata, for example:

  [namespace]
  (remove nil?
          (map #(get-function-meta namespace %) (ns-paths namespace))))

(defn build-map-arg-resolver [& kvs]
  (let [arg-map (apply hash-map kvs)]
