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
5 changes: 3 additions & 2 deletions src/yada/interceptors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@
ctx)))

;; else
(if-let [body-schema (get-in ctx [:resource :methods (:method ctx) :parameters :body])]
(if (s/check body-schema nil)
(if-let [params-schema (or (get-in ctx [:resource :methods (:method ctx) :parameters :body])
(get-in ctx [:resource :methods (:method ctx) :parameters :form]))]
(if (s/check params-schema nil)
(d/error-deferred
(ex-info "No body present but body is expected for request."
{:status 400}))
Expand Down
12 changes: 12 additions & 0 deletions test/yada/empty_body_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
(mock/content-type "application/x-www-form-urlencoded"))]
(is (= (:status @(handler req)) 400))))))

(deftest no-form-parameters
(let [resource
(resource {:consumes [{:media-type #{"application/x-www-form-urlencoded"}}]
:methods {:post {:parameters {:form {:foo sc/Int}}
:response (fn [ctx] "OK")}}})
handler (handler resource)]

(testing "no form body gives 400 issue #110"
(let [req (-> (mock/request :post "/" "")
(mock/content-type "application/x-www-form-urlencoded"))]
(is (= (:status @(handler req)) 400))))))

(deftest no-edn-body
(let [resource
(resource {:consumes [{:media-type #{"application/edn"}}]
Expand Down