nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: oliyh/martian
Pull request #30 (2016-12-08 17:51:33)

Allow :martian.core/body to be used as the body schema name.
If no :martian.core/body parameter fallback to previous behaviour of
matching the schema name.

This change makes it easy to call methods with anonymous body schemas from
compojure-api which don't have deterministic names (body34512 etc).


Patch:
diff --git a/README.md b/README.md
index 59689c6..354c813 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,11 @@ like that provided by [pedestal-api](https://github.com/oliyh/pedestal-api):
   (let [pet-id (-> (martian/response-for m :create-pet {:pet {:name "Doggy McDogFace" :type "Dog" :age 3}})
                    (get-in [:body :id]))]
 
+  ;; :martian.core/body can optionally be used in lieu of explicitly naming the body schema
+  (let [pet-id (-> (martian/response-for m :create-pet {::martian/body {:name "Doggy McDogFace" :type "Dog" :age 3}})
+                   (get-in [:body :id]))]
+
+
     ;; load the pet using the id
     (martian/response-for m :get-pet {:id pet-id})))
 
diff --git a/core/src/martian/interceptors.cljc b/core/src/martian/interceptors.cljc
index 32aff64..78eae81 100644
--- a/core/src/martian/interceptors.cljc
+++ b/core/src/martian/interceptors.cljc
@@ -38,9 +38,13 @@
 (def set-body-params
   {:name ::body-params
    :enter (fn [{:keys [params handler] :as ctx}]
-            (update ctx :request insert-or-merge :body (some-> (schema/coerce-data (:body-schema handler) params)
-                                                               first
-                                                               val)))})
+            (let [body (or
+                         (some->> (:martian.core/body params)
+                                  (schema/coerce-data (-> (:body-schema handler) first val)))
+                         (some-> (schema/coerce-data (:body-schema handler) params)
+                                 first
+                                 val))]
+              (update ctx :request insert-or-merge :body body)))})
 
 (def set-form-params
   {:name ::form-params


Test patch:
diff --git a/core/test/martian/core_test.cljc b/core/test/martian/core_test.cljc
index f907ed0..6e16648 100644
--- a/core/test/martian/core_test.cljc
+++ b/core/test/martian/core_test.cljc
@@ -188,7 +188,8 @@
             :url "https://api.org/pets/"
             :body {:id 123 :name "charlie"}}
            (request-for :create-pet {:pet {:id 123 :name "charlie"}})
-           (request-for :create-pet {:pet {:id "123" :name "charlie"}})))
+           (request-for :create-pet {:pet {:id "123" :name "charlie"}})
+           (request-for :create-pet {::martian/body {:id 123 :name "charlie"}})))
 
     (is (= {:method :post
             :url "https://api.org/users/"
Repository: oliyh/martian
Pull request #47 (2018-02-02 18:19:56)

Allow passing UUID for swagger uuid formatted string


Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index 398da23..ee4f997 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -87,10 +87,12 @@
            keyword
            definitions))
 
-(defn- schema-type [definitions {:keys [type enum $ref] :as param}]
+(defn- schema-type [definitions {:keys [type enum format $ref] :as param}]
   (cond
     enum (apply s/enum enum)
-    (= "string" type) s/Str
+    (= "string" type) (if (= "uuid" format)
+                        (s/cond-pre s/Str s/Uuid)
+                        s/Str)
     (= "integer" type) s/Int
     (= "boolean" type) s/Bool
     (or (= "object" type) $ref) (make-schema definitions param)


Test patch:
diff --git a/core/test/martian/schema_test.cljc b/core/test/martian/schema_test.cljc
index 9e30565..62eaaed 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -34,6 +34,14 @@
                                              :required true
                                              :type "unknown"}]))))
 
+(deftest uuid-test
+  (is (= (s/cond-pre s/Str s/Uuid)
+         (schema/make-schema {} {:name "uuid"
+                                 :in "path"
+                                 :required true
+                                 :type "string"
+                                 :format "uuid"}))))
+
 (deftest arrays-test
   (is (= [s/Str]
          (schema/make-schema {} {:name "tags"
Repository: oliyh/martian
Pull request #63 (2019-04-17 09:47:26)

Allow passing URI for swagger uri formatted string

oliyh: Hi @andrewmcveigh thank you very much for this contribution, it looks useful.

Please could you suggest an appropriate predicate for cljs?

Thanks!
andrewmcveigh: Added a predicate for cljs. Seeing as there's no URI object in plain js, I've gone for the `goog.Uri` one in closure.

Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index 774dffb..f9d330f 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -1,6 +1,7 @@
 (ns martian.schema
   (:require #?(:clj [schema.core :as s]
                :cljs [schema.core :as s :refer [AnythingSchema Maybe EnumSchema EqSchema]])
+            #?(:cljs [goog.Uri])
             [schema.coerce :as sc]
             [clojure.walk :refer [postwalk-replace]])
   #?(:clj (:import [schema.core AnythingSchema Maybe EnumSchema EqSchema])))
@@ -89,11 +90,16 @@
            keyword
            definitions))
 
+(def URI
+  #?(:clj java.net.URI
+     :cljs goog.Uri))
+
 (defn- schema-type [definitions {:keys [type enum format $ref] :as param}]
   (cond
     enum (apply s/enum enum)
-    (= "string" type) (if (= "uuid" format)
-                        (s/cond-pre s/Str s/Uuid)
+    (= "string" type) (case format
+                        "uuid" (s/cond-pre s/Str s/Uuid)
+                        "uri" (s/cond-pre s/Str URI)
                         s/Str)
     (= "integer" type) s/Int
     (= "boolean" type) s/Bool


Test patch:
diff --git a/core/test/martian/schema_test.cljc b/core/test/martian/schema_test.cljc
index 62eaaed..dd81d41 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -42,6 +42,14 @@
                                  :type "string"
                                  :format "uuid"}))))
 
+(deftest uri-test
+  (is (= (s/cond-pre s/Str schema/URI)
+         (schema/make-schema {} {:name "uri"
+                                 :in "path"
+                                 :required true
+                                 :type "string"
+                                 :format "uri"}))))
+
 (deftest arrays-test
   (is (= [s/Str]
          (schema/make-schema {} {:name "tags"
Repository: oliyh/martian
Pull request #77 (2019-12-20 17:18:33)

Fixes parameter-keys for open maps
https://github.com/oliyh/martian/pull/76 introduced a bug on `enrich-handler`
More specifically on `parameter-keys`, since it is calling `s/explicit-schema-key` on `s/Any`
and giving this error
```
Bad explicit key: schema.core.AnythingSchema@3c6f0b88
```

Making the client unusable (for this swagger.json)


Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index 0c3f098..c2f6c54 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -55,13 +55,18 @@
       :else
       ((sc/coercer! schema coercion-matchers) data))))
 
+(defn- extract-keys-from-map-schema [schema]
+  (->> (keys schema)
+       (filter s/specific-key?)
+       (map s/explicit-schema-key)))
+
 (defn parameter-keys [schemas]
   (mapcat
    (fn [schema]
      (when-let [s (from-maybe schema)]
        (cond
          (and (map? s) (not (record? s)))
-         (concat (map s/explicit-schema-key (keys s)) (parameter-keys (vals s)))
+         (concat (extract-keys-from-map-schema s) (parameter-keys (vals s)))
 
          (coll? s)
          (parameter-keys s)


Test patch:
diff --git a/core/test/martian/schema_test.cljc b/core/test/martian/schema_test.cljc
index 3dc99ba..2cd2f47 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -209,6 +209,10 @@
   (is (= [:foo]
          (schema/parameter-keys [{:foo s/Int}])))
 
+  (is (= [:foo]
+         (schema/parameter-keys [{:foo s/Int
+                                  s/Any s/Any}])))
+
   (is (= [:foo :bar]
          (schema/parameter-keys [{:foo s/Int}
                                  {:bar s/Str}])))
Repository: oliyh/martian
Pull request #146 (2022-02-13 22:31:09)

Add support for the "number" leaf schema.
This partially addresses #145


Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index 605dec6..6affba7 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -87,6 +87,7 @@
                         "uri" (s/cond-pre s/Str URI)
                         s/Str)
     (= "integer" type) s/Int
+    (= "number" type) s/Num
     (= "boolean" type) s/Bool
 
     :else


Test patch:
diff --git a/core/test/martian/schema_test.cljc b/core/test/martian/schema_test.cljc
index 98432d2..4a4e12d 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -35,6 +35,7 @@
 
 (deftest primitives-test
   (is (= {:id s/Int
+          :weight s/Num
           :name s/Str
           :dog? s/Bool
           :unknown s/Any}
@@ -42,6 +43,10 @@
                                              :in "path"
                                              :required true
                                              :type "integer"}
+                                            {:name "weight"
+                                             :in "path"
+                                             :required true
+                                             :type "number"}
                                             {:name "name"
                                              :in "path"
                                              :required true
Repository: oliyh/martian
Pull request #193 (2023-11-11 01:20:29)

OpenAPI's integer can have default value `inf`
https://github.com/openai/openai-openapi/blob/5c1857ea865e74e45e3b12064e0cc2396ef64be1/openapi.yaml#L6012C2-L6012C2

The default value for the integer is "inf".

robertluo: I have used my fork with this patch for the latest OpenAI API for a few days, and it looks good.

Patch:
diff --git a/core/src/martian/schema.cljc b/core/src/martian/schema.cljc
index 2cfd9ee..e2fb695 100644
--- a/core/src/martian/schema.cljc
+++ b/core/src/martian/schema.cljc
@@ -98,7 +98,13 @@
 
 (defn wrap-default [{:keys [default]} schema]
   (if (some? default)
-    (st/default schema default)
+    (let [default
+          ;patch for `inf` as a default value
+          (if (and (= schema s/Int) (= default "inf"))
+            #?(:clj Long/MAX_VALUE
+               :cljs Number.MAX_SAFE_INTEGER)
+            default)]
+      (st/default schema default))
     schema))
 
 (defn- schema-type [ref-lookup {:keys [type $ref] :as param}]


Test patch:
diff --git a/core/test/martian/schema_test.cljc b/core/test/martian/schema_test.cljc
index 202b8b1..1eff252 100644
--- a/core/test/martian/schema_test.cljc
+++ b/core/test/martian/schema_test.cljc
@@ -68,7 +68,8 @@
 (deftest default-values-test
   (testing "explaining and printing"
     (is (= '(default Int 123)
-           (s/explain (st/default s/Int 123)))))
+           (s/explain (schema/wrap-default {:default 123} s/Int))))
+    (is (= '(default Int) (take 2 (s/explain (schema/wrap-default {:default "inf"} s/Int))))))
 
   (let [schema (schema/schemas-for-parameters {} [{:name "id"
                                                    :in "path"