Skip to content

Commit

Permalink
backport arity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jul 8, 2024
1 parent 8309988 commit c1cd08d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Backport: use muuntaja in compojure.api.validator
* **BREAKING**: removed `api-defaults` vars
* add `-v1` suffix to vars
* Backport arity checks for `:body`, `:query`, `:headers

## 1.1.14 (2024-04-30)
* Remove potemkin [#445](https://github.com/metosin/compojure-api/issues/445)
Expand Down
21 changes: 17 additions & 4 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
; :swagger {:responses {200 {:schema User}
; 404 {:schema Error
; :description "Not Found"} }
; :paramerers {:query {:q s/Str}
; :parameters {:query {:q s/Str}
; :body NewUser}}}
(defmethod restructure-param :swagger [_ swagger acc]
(assoc-in acc [:swagger :swagger] swagger))
Expand Down Expand Up @@ -127,7 +127,11 @@
; second is the Schema to be coerced! against.
; Examples:
; :body [user User]
(defmethod restructure-param :body [_ [value schema] acc]
(defmethod restructure-param :body [_ [value schema :as bv] acc]
(when-not (= "true" (System/getProperty "compojure.api.meta.allow-bad-body"))
(assert (= 2 (count bv))
(str ":body should be [sym schema], provided: " bv
"\nDisable this check with -Dcompojure.api.meta.allow-bad-body=true")))
(-> acc
(update-in [:lets] into [value (src-coerce! schema :body-params :body)])
(assoc-in [:swagger :parameters :body] schema)))
Expand All @@ -136,7 +140,11 @@
; second is the Schema to be coerced! against.
; Examples:
; :query [user User]
(defmethod restructure-param :query [_ [value schema] acc]
(defmethod restructure-param :query [_ [value schema :as bv] acc]
(when-not (= "true" (System/getProperty "compojure.api.meta.allow-bad-query"))
(assert (= 2 (count bv))
(str ":query should be [sym schema], provided: " bv
"\nDisable this check with -Dcompojure.api.meta.allow-bad-query=true")))
(-> acc
(update-in [:lets] into [value (src-coerce! schema :query-params :string)])
(assoc-in [:swagger :parameters :query] schema)))
Expand All @@ -145,7 +153,12 @@
; second is the Schema to be coerced! against.
; Examples:
; :headers [headers Headers]
(defmethod restructure-param :headers [_ [value schema] acc]
(defmethod restructure-param :headers [_ [value schema :as bv] acc]
(when-not (= "true" (System/getProperty "compojure.api.meta.allow-bad-headers"))
(assert (= 2 (count bv))
(str ":headers should be [sym schema], provided: " bv
"\nDisable this check with -Dcompojure.api.meta.allow-bad-headers=true")))

(-> acc
(update-in [:lets] into [value (src-coerce! schema :headers :string)])
(assoc-in [:swagger :parameters :header] schema)))
Expand Down

0 comments on commit c1cd08d

Please sign in to comment.