Skip to content

Commit

Permalink
backport muuntaja json parse
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed May 14, 2024
1 parent 6b8b9c6 commit 6f98c87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## NEXT
* drop support for Clojure 1.8
* upgrade cheshire 5.13.0
* Backport: use muuntaja in compojure.api.validator

## 1.1.14 (2024-04-30)
* Remove potemkin [#445](https://github.com/metosin/compojure-api/issues/445)
Expand Down
3 changes: 3 additions & 0 deletions src/compojure/api/methods.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(ns compojure.api.methods)

(def all-methods #{:get :head :patch :delete :options :post :put})
9 changes: 5 additions & 4 deletions src/compojure/api/validator.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
(ns compojure.api.validator
(:require [compojure.api.swagger :as swagger]
[cheshire.core :as cheshire]
[compojure.api.impl.json :as json]
[ring.swagger.validator :as rsv]
[muuntaja.core :as m]
[compojure.api.middleware :as mw]))

(defn validate
"Validates a api. If the api is Swagger-enabled, the swagger-spec
"Validates an api. If the api is Swagger-enabled, the swagger-spec
is requested and validated against the JSON Schema. Returns either
the (valid) api or throws an exception. Requires lazily the
ring.swagger.validator -namespace allowing it to be excluded, #227"
[api]
(when-let [uri (swagger/swagger-spec-path api)]
(let [{status :status :as response} (api {:request-method :get
:uri uri
mw/rethrow-exceptions? true})
body (-> response :body slurp (cheshire/parse-string true))]
::mw/rethrow-exceptions? true})
body (->> response :body (m/decode json/muuntaja "application/json"))]

(when-not (= status 200)
(throw (ex-info (str "Coudn't read swagger spec from " uri)
Expand Down

0 comments on commit 6f98c87

Please sign in to comment.