Skip to content

Commit

Permalink
Merge branch '1.1.x' of github.com:metosin/compojure-api into 1.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jun 17, 2024
2 parents af472c9 + 7e4f63b commit 8309988
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/compojure/api/coercion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[compojure.api.request :as request]
[compojure.api.coercion.core :as cc]
;; side effects
compojure.api.coercion.register-schema
compojure.api.coercion.register-spec)
compojure.api.coercion.schema
compojure.api.coercion.spec)
(:import (compojure.api.coercion.core CoercionError)))

(def default-coercion :schema)
Expand Down
8 changes: 0 additions & 8 deletions src/compojure/api/coercion/register_schema.clj

This file was deleted.

8 changes: 0 additions & 8 deletions src/compojure/api/coercion/register_spec.clj

This file was deleted.

6 changes: 3 additions & 3 deletions src/compojure/api/coercion/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
[compojure.api.coercion.core :as cc]
[clojure.walk :as walk]
[schema.core :as s]
[compojure.api.common :as common]
;; side effects
compojure.api.coercion.register-schema)
[compojure.api.common :as common])
(:import (java.io File)
(schema.core OptionalKey RequiredKey)
(schema.utils ValidationError NamedError)))
Expand Down Expand Up @@ -86,3 +84,5 @@
(->SchemaCoercion :schema options))

(def default-coercion (create-coercion default-options))

(defmethod cc/named-coercion :schema [_] default-coercion)
6 changes: 3 additions & 3 deletions src/compojure/api/coercion/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
[clojure.walk :as walk]
[compojure.api.coercion.core :as cc]
[spec-tools.swagger.core :as swagger]
[compojure.api.common :as common]
;; side effects
compojure.api.coercion.register-spec)
[compojure.api.common :as common])
(:import (clojure.lang IPersistentMap)
(schema.core RequiredKey OptionalKey)
(spec_tools.core Spec)
Expand Down Expand Up @@ -151,3 +149,5 @@
(->SpecCoercion :spec options))

(def default-coercion (create-coercion default-options))

(defmethod cc/named-coercion :spec [_] default-coercion)
3 changes: 2 additions & 1 deletion src/compojure/api/resource.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(ns compojure.api.resource
(:require [compojure.api.routes :as routes]
[compojure.api.coerce :as coerce]
[compojure.api.methods :as methods]
[ring.swagger.common :as rsc]
[schema.core :as s]
[plumbing.core :as p]
[compojure.api.middleware :as mw]))

(def ^:private +mappings+
{:methods #{:get :head :patch :delete :options :post :put}
{:methods methods/all-methods
:parameters {:query-params [:query-params :query :string true]
:body-params [:body-params :body :body false]
:form-params [:form-params :formData :string true]
Expand Down
29 changes: 28 additions & 1 deletion src/compojure/api/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
[linked.core :as linked]
[compojure.response]
[schema.core :as s])
(:import [clojure.lang AFn IFn Var]))
(:import (clojure.lang AFn IFn Var IDeref)
(java.io Writer)))

;;
;; Route records
Expand Down Expand Up @@ -47,6 +48,19 @@
(update-in route [0] (fn [uri] (if (str/blank? uri) "/" uri))))
(-get-routes handler options))))

(defn get-static-context-routes
([handler]
(get-static-context-routes handler nil))
([handler options]
(filter (fn [[_ _ info]] (get info :static-context?))
(get-routes handler options))))

(defn- realize-childs [route]
(update route :childs #(if (instance? IDeref %) @% %)))

(defn- filter-childs [route]
(update route :childs (partial filter (partial satisfies? Routing))))

(defrecord Route [path method info childs handler]
Routing
(-get-routes [this options]
Expand All @@ -72,12 +86,25 @@
IFn
(invoke [_ request]
(handler request))
(invoke [_ request respond raise]
(handler request respond raise))

(applyTo [this args]
(AFn/applyToHelper this args)))

(defn create [path method info childs handler]
(->Route path method info childs handler))

(defmethod print-method Route
[this ^Writer w]
(let [childs (some-> this realize-childs filter-childs :childs seq vec)]
(.write w (str "#Route"
(cond-> (dissoc this :handler :childs)
(not (:path this)) (dissoc :path)
(not (seq (:info this))) (dissoc :info)
(not (:method this)) (dissoc :method)
childs (assoc :childs childs))))))

;;
;; Invalid route handlers
;;
Expand Down

0 comments on commit 8309988

Please sign in to comment.