File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3737 " (:doc (meta #'compojure.api.middleware/api-middleware)))}
3838 api
3939 [& body]
40- (let [[options handlers] (common/extract-parameters body)
40+ (let [[options handlers] (common/extract-parameters body false )
4141 options (rsc/deep-merge api-defaults options)
4242 handler (apply core/routes handlers)
4343 routes (routes/get-routes handler (:api options))
Original file line number Diff line number Diff line change 1212 3. else => `{}`
1313
1414 Returns a tuple with parameters and body without the parameters"
15- [c]
15+ [c expect-body ]
1616 (cond
17- (plain-map? (first c))
17+ (and ( plain-map? (first c)) ( or ( not expect-body) ( seq ( rest c)) ))
1818 [(first c) (seq (rest c))]
1919
2020 (keyword? (first c))
Original file line number Diff line number Diff line change 318318 (seq responses) (assoc :responses (apply merge responses))))
319319
320320(defn restructure [method [path arg & args] {:keys [context?]}]
321- (let [[options body] (extract-parameters args)
321+ (let [[options body] (extract-parameters args true )
322322 [path-string lets arg-with-request arg] (destructure-compojure-api-request path arg)
323323
324324 {:keys [lets
Original file line number Diff line number Diff line change 7676 (let [[path body] (if (string? (first body))
7777 [(first body) (rest body)]
7878 [" /swagger.json" body])
79- [extra-info] (extract-parameters body)]
8079 (GET path request
80+ [extra-info] (common/extract-parameters body false )]
8181 :no-doc true
8282 :name ::swagger
8383 (let [runtime-info (rsm/get-swagger-data request)
Original file line number Diff line number Diff line change 11(ns compojure.api.common-test
2- (:require [compojure.api.common :refer :all ]
2+ (:require [compojure.api.common :as common ]
33 [midje.sweet :refer :all ]))
44
55(fact " group-with"
6- (group-with pos? [1 -10 2 -4 -1 999 ]) => [[1 2 999 ] [-10 -4 -1 ]]
7- (group-with pos? [1 2 999 ]) => [[1 2 999 ] nil ])
6+ (common/group-with pos? [1 -10 2 -4 -1 999 ]) => [[1 2 999 ] [-10 -4 -1 ]]
7+ (common/group-with pos? [1 2 999 ]) => [[1 2 999 ] nil ])
8+
9+ (fact " extract-parameters"
10+
11+ (facts " expect body"
12+ (common/extract-parameters [] true ) => [{} nil ]
13+ (common/extract-parameters [{:a 1 }] true ) => [{} [{:a 1 }]]
14+ (common/extract-parameters [:a 1 ] true ) => [{:a 1 } nil ]
15+ (common/extract-parameters [{:a 1 } {:b 2 }] true ) => [{:a 1 } [{:b 2 }]]
16+ (common/extract-parameters [:a 1 {:b 2 }] true ) => [{:a 1 } [{:b 2 }]])
17+
18+ (facts " don't expect body"
19+ (common/extract-parameters [] false ) => [{} nil ]
20+ (common/extract-parameters [{:a 1 }] false ) => [{:a 1 } nil ]
21+ (common/extract-parameters [:a 1 ] false ) => [{:a 1 } nil ]
22+ (common/extract-parameters [{:a 1 } {:b 2 }] false ) => [{:a 1 } [{:b 2 }]]
23+ (common/extract-parameters [:a 1 {:b 2 }] false ) => [{:a 1 } [{:b 2 }]]))
Original file line number Diff line number Diff line change 7979; ; Facts
8080; ;
8181
82+ (facts " core routes"
83+
84+ (fact " keyword options"
85+ (let [route (GET " /ping" []
86+ :return String
87+ (ok " kikka" ))]
88+ (route {:request-method :get :uri " /ping" }) => (contains {:body " kikka" })))
89+
90+ (fact " map options"
91+ (let [route (GET " /ping" []
92+ {:return String}
93+ (ok " kikka" ))]
94+ (route {:request-method :get :uri " /ping" }) => (contains {:body " kikka" })))
95+
96+ (fact " map return"
97+ (let [route (GET " /ping" []
98+ {:body " kikka" })]
99+ (route {:request-method :get :uri " /ping" }) => (contains {:body " kikka" }))))
100+
82101(facts " middleware ordering"
83102 (let [app (api
84103 (middleware [middleware* [middleware* 2 ]]
You can’t perform that action at this time.
0 commit comments