Skip to content

Commit bae6d47

Browse files
committed
Fix detecting path-parameters from uri
Fixes #196
1 parent 1a32ed3 commit bae6d47

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
* Fixed path parameter handling in cases where path parameter is followed by an extension
4+
([#196](https://github.com/metosin/compojure-api/issues/196), [metosin/ring-swagger#82](https://github.com/metosin/ring-swagger/issues/82))
35
* [Updated ring-swagger](https://github.com/metosin/ring-swagger/blob/master/CHANGELOG.md#Unreleased)
46
* Added `compojure.api.exception/with-logging` helper to add logging to exception handlers.
57
* Check extended wiki guide on [exception handling](https://github.com/metosin/compojure-api/wiki/Exception-handling#logging)

src/compojure/api/swagger.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@
151151
;; ensure path parameters
152152
;;
153153

154-
(defn path-params [s]
155-
(map (comp keyword second) (re-seq #":(.[^:|(/]*)[/]?" s)))
154+
(defn path-params
155+
"Finds path-parameter keys in an uri.
156+
157+
Regex copied from Clout and Ring-swagger."
158+
[s]
159+
(map (comp keyword second) (re-seq #":([\p{L}_][\p{L}_0-9-]*)" s)))
156160

157161
(defn string-path-parameters [uri]
158162
(let [params (path-params uri)]

test/compojure/api/swagger_test.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,14 @@
169169
'(r1 r2)))
170170
=> {:paths {"/:id" {:get {:parameters {:path {:id String}}}}
171171
"/kukka/:id" {:get {:parameters {:path {:id Long}}}}}})
172+
173+
(fact "string-path-parameters"
174+
(string-path-parameters "/:foo.json") => {:foo String})
175+
176+
(fact "path params followed by an extension"
177+
(first
178+
(swagger-info
179+
'(GET* "/:foo.json" []
180+
:path-params [foo :- String]
181+
identity)))
182+
=> {:paths {"/:foo.json" {:get {:parameters {:path {:foo String}}}}}})

0 commit comments

Comments
 (0)