 ;; ----- ensure matcher in routes -----
 
 
-(def make-uri-matcher
-  "Given a route spec map containing :uri key with URI-pattern as value, return a matcher fn to match the URI. If the
-  route spec does not contain :uri key then it is left intact."
+(def ^{:arglists '([route-spec matchex])} ensure-matchex
+  "Given a route spec not containing the :matchex key, assoc specified matchex into the spec. If the route spec already
+  contains :matchex then leave it intact."
+  (make-ensurer :matchex
+    (fn [spec matchex]
+      (assoc spec :matchex matchex))))
+
+
+(def ^{:arglists '([route-spec uri-finder])} make-uri-matcher
+  "Given a route spec not containing the :matcher key and containing URI-pattern string as value (found by uri-finder),
+  create a URI matcher and add it under the :matcher key. If the route spec already contains the :matcher key or if it
+  does not contain URI-pattern then the route spec is left intact. When adding matcher also add matchex unless the
+  :matchex key already exists."
   (make-ensurer :matcher
     (fn [spec uri-finder]
       (when-not (map? spec)

      (if-let [uri-pattern (uri-finder spec)]  ; assoc matcher only if URI matcher is intended
        (do
          (when-not (string? uri-pattern)
            (i/expected "URI pattern to be retrievable as a string value" spec))
          (let [uri-template (i/parse-uri-template i/default-separator uri-pattern)
                ensure-matchex (make-ensurer :matchex
                                 (fn [spec x]
                                   (assoc spec :matchex x)))]
            (-> spec
              (assoc :matcher (fn [request]
                                (when-let [params (Util/matchURI ^String (:uri request) uri-template)]

                                                  `(when (~method (:request-method ~request))
                                                     {}))))))
        spec))))
