diff --git a/project.clj b/project.clj index 7dbda03..a3459c8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject prismatic/fnhouse "0.2.2-SNAPSHOT" +(defproject tiensonqin/fnhouse-hacks "0.2.2-SNAPSHOT" :description "Transform lightly-annotated functions into a full-fledged web service" :license {:name "Eclipse Public License - v 1.0" :url "http://www.eclipse.org/legal/epl-v10.html" diff --git a/src/fnhouse/handlers.clj b/src/fnhouse/handlers.clj index 376c9f6..bfdc5b9 100644 --- a/src/fnhouse/handlers.clj +++ b/src/fnhouse/handlers.clj @@ -142,7 +142,7 @@ (letk [[method path] (path-and-method var) [{doc ""} {responses {}}] (meta var) [{resources {}} {request {}}] (pfnk/input-schema @var) - [{uri-args s/Any} {query-params s/Any} {body nil}] request] + [{uri-args s/Any} {query-params s/Any} {body nil} {custom nil}] request] (let [source-map (source-map var) explicit-uri-args (dissoc (default-map-schema uri-args) s/Keyword) raw-declared-args (routes/uri-arg-ks path) @@ -155,7 +155,8 @@ :body body :uri-args (merge (map-from-keys (constantly String) declared-args) - explicit-uri-args)} + explicit-uri-args) + :custom custom} :responses responses :resources resources diff --git a/src/fnhouse/middleware.clj b/src/fnhouse/middleware.clj index 293cfbc..245649b 100644 --- a/src/fnhouse/middleware.clj +++ b/src/fnhouse/middleware.clj @@ -34,6 +34,7 @@ {:uri-args [coerce/string-coercion-matcher] :query-params [coerce/string-coercion-matcher] :body [coerce/json-coercion-matcher] + :custom [coerce/string-coercion-matcher] :response []}) (s/defn coercing-walker @@ -54,7 +55,7 @@ (if-let [error (utils/error-val res)] (throw (ex-info (format "Request: [%s]
==> Error: [%s]
==> Context: [%s]" - (pr-str (select-keys request [:uri :query-string :body])) + (pr-str (select-keys request [:uri :query-string :body :custom])) (pr-str error) context) {:type :coercion-error @@ -62,13 +63,14 @@ :data data :error error :context context})) + res)))))) (defn request-walker "Given a custom input coercer, compile a function for coercing and validating requests (uri-args, query-params, and body)." [input-coercer handler-info] - (let [request-walkers (for-map [k [:uri-args :query-params :body] + (let [request-walkers (for-map [k [:uri-args :query-params :body :custom] :let [schema (safe-get-in handler-info [:request k])] :when schema] k diff --git a/src/fnhouse/schemas.clj b/src/fnhouse/schemas.clj index 13d7d7a..727d3bc 100644 --- a/src/fnhouse/schemas.clj +++ b/src/fnhouse/schemas.clj @@ -61,7 +61,9 @@ :request {:uri-args {s/Keyword Schema} :query-params Schema - :body (s/maybe Schema)} + :body (s/maybe Schema) + :custom (s/maybe Schema)} + :responses {(s/named s/Int "status code") (s/named Schema "response body schema")}