Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/fnhouse/handlers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/fnhouse/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,21 +55,22 @@
(if-let [error (utils/error-val res)]
(throw (ex-info
(format "Request: [%s]<BR>==> Error: [%s]<BR>==> 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
:schema schema
: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
Expand Down
4 changes: 3 additions & 1 deletion src/fnhouse/schemas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")}

Expand Down