Repository: oliyh/martian
Pull request #76 (2019-12-20 10:56:26)

Additional params fix
See #72 & #73 


Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index f82a96b..0c3f098 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -140,7 +140,7 @@
 
                 (= "object" type)
                 (cond-> (schemas-for-parameters definitions (map (fn [[name p]] (assoc p :name name)) properties))
-                  additionalProperties (assoc (s/optional-key s/Any) s/Any))
+                  additionalProperties (assoc s/Any s/Any))
 
                 :else
                 (schema-type definitions param))
diff --git a/core/src/martian/swagger.cljc b/core/src/martian/swagger.cljc
index f14897f..17a0deb 100644
--- a/core/src/martian/swagger.cljc
+++ b/core/src/martian/swagger.cljc
@@ -46,15 +46,11 @@
             (keyword param-name)
             %) parts)))
 
-(defn- ->handler
-  [{:keys [definitions] :as swagger-map}
-   path-item-parameters
-   url-pattern
-   [method swagger-definition]]
+(defn- ->handler [{:keys [definitions] :as swagger-map} 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 (concat path-item-parameters (:parameters swagger-definition))]
+          parameters (:parameters swagger-definition)]
       {:path uri
        :path-parts path-parts
        :method method
@@ -79,7 +75,6 @@
      (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/schema_test.cljc b/core/test/martian/schema_test.cljc
index b9dae35..3dc99ba 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -20,9 +20,9 @@
                                     :description ""
                                     :required    true
                                     :schema      {:$ref "#/definitions/Body55523"}})]
-    (is (= {(s/optional-key :name)   (s/maybe {(s/optional-key s/Any) s/Any})
-            (s/optional-key :age)    (s/maybe {(s/optional-key s/Any) s/Any})
-            (s/optional-key :colour) (s/maybe {(s/optional-key s/Any) s/Any})}
+    (is (= {(s/optional-key :name)   (s/maybe {s/Any s/Any})
+            (s/optional-key :age)    (s/maybe {s/Any s/Any})
+            (s/optional-key :colour) (s/maybe {s/Any s/Any})}
            schema))))
 
 (deftest enum-test
@@ -133,17 +133,19 @@
               :required true
               :type "integer"}]))))
   (testing "object with additional properties"
-    (is (= {:Pet {:CamelBodyKey          s/Int
-                  (s/optional-key s/Any) s/Any}}
-           (schema/schemas-for-parameters
-            {:Pet {:type                 "object"
-                   :additionalProperties true
-                   :properties           {:CamelBodyKey {:type     "integer"
-                                                         :required true}}}}
-            [{:name     "Pet"
-              :in       "path"
-              :required true
-              :schema   {:$ref "#/definitions/Pet"}}]))))
+    (let [schema (:Pet (schema/schemas-for-parameters
+                         {:Pet {:type                 "object"
+                                :additionalProperties true
+                                :properties           {:CamelBodyKey {:type     "integer"
+                                                                      :required true}}}}
+                         [{:name     "Pet"
+                           :in       "path"
+                           :required true
+                           :schema   {:$ref "#/definitions/Pet"}}]))]
+      (is (= {:CamelBodyKey s/Int
+              s/Any         s/Any} schema))
+      (is (s/validate schema {:CamelBodyKey 42
+                              :AdditionalDetails {"GoodBoy" true}}))))
   (testing "object with empty properties"
     (is (= {:Pet {}}
            (schema/schemas-for-parameters
diff --git a/core/test/martian/swagger_test.cljc b/core/test/martian/swagger_test.cljc
deleted file mode 100644
index 84c851c..0000000
--- a/core/test/martian/swagger_test.cljc
+++ /dev/null
@@ -1,20 +0,0 @@
-(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)))))