Repository: oliyh/martian (clojure)

Issue:
[Bug] Martian is not respecting Path Item Object's parameters
In the OpenAPI-Specification 2.0 (same as Swagger 2.0) you can nest parameters like this:
```json
{
  "paths": {
    "/api/pets/{id}": {
      "get": {
        "method": "get",
        "parameters": [
          {
            "name": "watch",
            "type": "string",
            "in": "query"
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "type": "string",
          "in": "path",
          "required": true
        }
      ]
    }
  }
}

```

But `martian` is only looking into `parameters` inside `get` (or any other http verb)

Reference:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#pathItemObject

Pull request:
Fixes #74

Patch:
diff --git a/core/src/martian/swagger.cljc b/core/src/martian/swagger.cljc
index 17a0deba..f14897fc 100644
--- a/core/src/martian/swagger.cljc
+++ b/core/src/martian/swagger.cljc
@@ -46,11 +46,15 @@
             (keyword param-name)
             %) parts)))
 
-(defn- ->handler [{:keys [definitions] :as swagger-map} url-pattern [method swagger-definition]]
+(defn- ->handler
+  [{:keys [definitions] :as swagger-map}
+   path-item-parameters
+   url-pattern
+   [method swagger-definition]]
   (when-let [route-name (some-> (:operationId swagger-definition) ->kebab-case-keyword)]
     (let [path-parts (tokenise-path url-pattern)
           uri (string/join (map str path-parts))
-          parameters (:parameters swagger-definition)]
+          parameters (concat path-item-parameters (:parameters swagger-definition))]
       {:path uri
        :path-parts path-parts
        :method method
@@ -75,6 +79,7 @@
      (fn [handlers url-pattern swagger-handlers]
        (into handlers (keep (partial ->handler
                                      swagger-spec
+                                     (:parameters swagger-handlers)
                                      url-pattern)
                             swagger-handlers)))
      []


Test patch:
diff --git a/core/test/martian/swagger_test.cljc b/core/test/martian/swagger_test.cljc
new file mode 100644
index 00000000..84c851cb
--- /dev/null
+++ b/core/test/martian/swagger_test.cljc
@@ -0,0 +1,20 @@
+(ns martian.swagger-test
+  (:require [clojure.test :refer :all]
+            [schema.core :as s]
+            [martian.swagger :as swagger]))
+
+(deftest path-item-obj-parameters-test
+  (let [[get-handler delete-handler] (swagger/swagger->handlers {"paths" {"/pets/{id}" {"get"        {"operationId" "getPetById"
+                                                                               "method"      "get"
+                                                                               "parameters"  [{"name" "watch"
+                                                                                               "in"   "query"}]}
+                                                                 "delete"     {"operationId" "deletePetById"
+                                                                               "method"      "delete"
+                                                                               "parameters"  [{"name" "prettyprint"
+                                                                                               "in"   "query"}]}
+                                                                 "parameters" [{"name"     "id"
+                                                                                "in"       "path"
+                                                                                "type"     "string"
+                                                                                "required" "true"}]}}})]
+    (is (= {:id s/Str} (:path-schema get-handler)))
+    (is (= {:id s/Str} (:path-schema delete-handler)))))