Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmf adapter #475

Draft
wants to merge 5 commits into
base: 1.1.x
Choose a base branch
from
Draft
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run tests

on:
push:
branches: [master, "1.1.x"]
branches: [master, "1.1.x", "rmf-adapter"]
pull_request:
branches: [master, "1.1.x"]

Expand Down
1 change: 1 addition & 0 deletions examples/thingie/src/examples/thingie.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [ring.util.http-response :refer :all]
[compojure.api.sweet :refer :all]
[compojure.api.upload :refer :all]
compojure.api.middleware.rmf-muuntaja-adapter
[schema.core :as s]
ring.swagger.json-schema-dirty
ring.middleware.multipart-params.byte-array
Expand Down
65 changes: 38 additions & 27 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,68 @@
:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo
:comments "same as Clojure"}
:scm {:name "git"
:url "https://github.com/metosin/compojure-api"}
:dependencies [[prismatic/plumbing "0.6.0"]
[cheshire "5.13.0"]
[compojure "1.6.1"]
[prismatic/schema "1.1.12"]
[org.tobereplaced/lettercase "1.0.0"]
[frankiesardo/linked "1.3.0"]
[ring-middleware-format "0.7.4"]
:dependencies [[prismatic/schema "1.1.12"]
[prismatic/plumbing "0.5.5"]
[ikitommi/linked "1.3.1-alpha1"] ;; waiting for the original
[metosin/muuntaja "0.6.6"]
[com.fasterxml.jackson.datatype/jackson-datatype-joda "2.10.1"]
[ring/ring-core "1.8.0"]
[compojure "1.6.1" ]
[metosin/spec-tools "0.10.6"]
[metosin/ring-http-response "0.9.1"]
[metosin/ring-swagger-ui "3.24.3"]
[metosin/ring-swagger "1.0.0"]
[metosin/ring-swagger-ui "2.2.10"]]

;; Fix dependency conflicts
[clj-time "0.15.2"]
[joda-time "2.10.5"]
[riddley "0.2.0"]]
:pedantic? :abort
:profiles {:uberjar {:aot :all
:ring {:handler examples.thingie/app}
:source-paths ["examples/thingie/src"]
:dependencies [[org.clojure/clojure "1.9.0"]
[http-kit "2.3.0"]
[reloaded.repl "0.2.4"]
[com.stuartsierra/component "0.4.0"]]}
:dev {:jvm-opts ["-Dcompojure.api.core.allow-dangerous-middleware=true"]
:repl-options {:init-ns user}
:plugins [[lein-clojars "0.9.1"]
:dev {:plugins [[lein-clojars "0.9.1"]
[lein-midje "3.2.1"]
[lein-ring "0.12.0"]
[lein-ring "0.12.5"]
[funcool/codeina "0.5.0"]]
:dependencies [[org.clojure/clojure "1.9.0"]
;; bump
[fipp "0.6.26"]
[metosin/spec-tools "0.10.6"]
[metosin/muuntaja "0.6.6"]
[metosin/jsonista "0.2.5"]
[com.fasterxml.jackson.datatype/jackson-datatype-joda "2.10.1"]
[slingshot "0.12.2"]
[peridot "0.5.1"]
[javax.servlet/servlet-api "2.5"]
[midje "1.9.9"]
[org.clojure/core.unify "0.6.0"]
[org.clojure/core.async "0.6.532"]
[javax.servlet/javax.servlet-api "4.0.1"]
[peridot "0.5.2"]
[com.stuartsierra/component "0.4.0"]
[expound "0.8.2"]
[metosin/jsonista "0.2.5"]
[reloaded.repl "0.2.4"]
[midje "1.9.9" :exclusions [commons-codec org.clojure/tools.namespace]]
[metosin/muuntaja-msgpack "0.6.6"]
[metosin/muuntaja-yaml "0.6.6"]
[org.immutant/immutant "2.1.10"]
[http-kit "2.3.0"]
[criterium "0.4.5"]]
[criterium "0.4.5"]
;; compojure.api.integration-test
[ring-middleware-format "0.7.4" :exclusions [org.clojure/core.memoize]]]
:ring {:handler examples.thingie/app
:reload-paths ["src" "examples/thingie/src"]}
:source-paths ["examples/thingie/src" "examples/thingie/dev-src"]
:main examples.server}
:perf {:jvm-opts ^:replace ["-server"
"-Xmx4096m"
"-Dclojure.compiler.direct-linking=true"]}
:logging {:dependencies [[org.clojure/tools.logging "0.5.0"]]}
:logging {:dependencies [[org.clojure/tools.logging "0.5.0"]
[org.slf4j/jcl-over-slf4j "1.7.30"]
[org.slf4j/jul-to-slf4j "1.7.30"]
[org.slf4j/log4j-over-slf4j "1.7.30"]
[ch.qos.logback/logback-classic "1.2.3" ]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.1"]]}
:1.11 {:dependencies [[org.clojure/clojure "1.11.3"]]}
:1.12 {:dependencies [[org.clojure/clojure "1.12.0-alpha11"]]}}
:1.12 {:dependencies [[org.clojure/clojure "1.12.0-alpha11"]]}
:async {:jvm-opts ["-Dcompojure-api.test.async=true"]
:dependencies [[manifold "0.1.8" :exclusions [org.clojure/tools.logging]]]}}
:eastwood {:namespaces [:source-paths]
:add-linters [:unused-namespaces]}
:codeina {:sources ["src"]
Expand Down
3 changes: 2 additions & 1 deletion src/compojure/api/coercion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[compojure.api.request :as request]
[compojure.api.coercion.core :as cc]
;; side effects
compojure.api.coercion.schema
[compojure.api.coercion.schema :as cschema]
compojure.api.coercion.spec)
(:import (compojure.api.coercion.core CoercionError)))

Expand All @@ -23,6 +23,7 @@
(nil? coercion) nil
(keyword? coercion) (cc/named-coercion coercion)
(satisfies? cc/Coercion coercion) coercion
(fn? coercion) (cschema/create-coercion coercion)
:else (throw (ex-info (str "invalid coercion " coercion) {:coercion coercion}))))

(defn get-apidocs [maybe-coercion spec info]
Expand Down
5 changes: 5 additions & 0 deletions src/compojure/api/exception.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
[e data req]
(response/bad-request {:errors (stringify-error (su/error-val data))}))

(defn http-response-handler
"reads response from ex-data :response"
[_ {:keys [response]} _]
response)

(defn schema-error-handler
"Creates error response based on Schema error."
[e data req]
Expand Down
16 changes: 10 additions & 6 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
[ring.swagger.json-schema :as js]
[schema.core :as s]
[schema-tools.core :as st]
[compojure.api.coerce :as coerce]
compojure.core))
[compojure.api.coercion :as coercion]
[compojure.api.help :as help]
compojure.core
compojure.api.compojure-compat
[compojure.api.common :as common]))

(def +compojure-api-request+
"lexically bound ring-request for handlers."
Expand All @@ -33,9 +36,10 @@
(s/defn src-coerce!
"Return source code for coerce! for a schema with coercion type,
extracted from a key in a ring request."
[schema, key, type :- mw/CoercionType]
(assert (not (#{:query :json} type)) (str type " is DEPRECATED since 0.22.0. Use :body or :string instead."))
`(coerce/coerce! ~schema ~key ~type ~+compojure-api-request+))
([schema, key, type]
(src-coerce! schema, key, type, true))
([schema, key, type, keywordize?]
`(coercion/coerce-request! ~schema ~key ~type ~keywordize? false ~+compojure-api-request+)))

(defn- convert-return [schema]
{200 {:schema schema
Expand Down Expand Up @@ -303,7 +307,7 @@
_ (assert (not parameters) ":parameters is deprecated with 1.0.0, use :swagger instead.")

;; response coercion middleware, why not just code?
middleware (if (seq responses) (conj middleware `[coerce/body-coercer-middleware (common/merge-vector ~responses)]) middleware)]
middleware (if (seq responses) (conj middleware `[coercion/wrap-coerce-response (common/merge-vector ~responses)]) middleware)]

(if context?

Expand Down
Loading
Loading