@ikitommi Hello! I noticed another Swagger validation error and I think I've tracked it down to the 'ANY' macro:
=> (def app (context "/a" []
(routes
(context "/" []
(ANY "/*" [] identity)))))
=> (extract-paths app)
#linked/map [["/a/*" {nil {}}]]
I think that nil
is contributing to a Swagger doc which looks like:
"/*": {
"": {
"responses": {
"default": {
"description": ""
}
}
}
}
It's the empty string key that's causing the error
I was hoping for some advice regarding the best place to implement a fix for this. I'm not sure if it's compojure-api which should ignore ANY
in extract-paths
or something in spec-tools
, or something else.
=> (swagger2/swagger-json {:paths {"/*" {nil {}}}})
{:swagger "2.0", :info {:title "Swagger API", :version "0.0.1"}, :produces ["application/json"], :consumes ["application/json"], :paths {"/*" {nil {:responses {:default {:description ""}}}}}, :definitions {}}
I guess the other question is, when it encounters ANY what should the behaviour be? Should extract-paths
create an entry for each HTTP verb or omit the path?
@acron hmm… I think ANY could map to all verbs. Because all of them work. And I believe the fix should be here: https://github.com/metosin/compojure-api/blob/master/src/compojure/api/routes.clj#L67-L76
Thanks, I will take a look!
@ikitommi I'm worried that fiddling with this will impact the way routes are matched, or am I wrong?
no, it’s just docs. the routing still uses Compojure directly.
if you evaluate any route macro at repl, you’ll see a Route
record. It has a :handler
key, which is used for actual dispatch + a lot of extra info, extracted for docs.
(-get-routes [this options]
(let [this (-> this realize-childs)
valid-childs (filter-routes this options)
make-method-path-fn (fn [m] [path m info])]
(if (-> this filter-childs :childs seq)
(vec
(for [[p m i] (mapcat #(-get-routes % options) valid-childs)]
[(->paths path p) m (rsc/deep-merge info i)]))
(into [] (cond
(and path method) [(make-method-path-fn method)]
path (mapv make-method-path-fn #{:get :post :head :etc}))))))
something like this?method
is nil
in the case of ANY
looks good to me.
@ikitommi Thanks, I've put in a PR. No rush though https://github.com/metosin/compojure-api/pull/346