Skip to content

Commit bd71f60

Browse files
committed
[housekeeping] Remove reflective calls, formatting
1 parent 84aa4e9 commit bd71f60

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/navi/transform.clj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
RequestBody]))
3232

3333
(defn- transform-object
34-
[schema]
34+
[^ObjectSchema schema]
3535
(let [required (->> schema
3636
.getRequired
3737
(into #{}))
@@ -41,22 +41,24 @@
4141
(into []))]
4242
(into [:map {:closed false}] schemas)))
4343

44-
(defn- transform-array [schema]
44+
(defn- transform-array
45+
[^ArraySchema schema]
4546
(let [items (.getItems schema)]
4647
[:sequential
4748
(if (nil? items)
4849
any?
4950
(p/transform items))]))
5051

51-
(defn- transform-composed [schema]
52+
(defn- transform-composed
53+
[^ComposedSchema schema]
5254
(let [[schemas compose-as] (cond
5355
(< 0 (count (.getAnyOf schema)))
5456
[(.getAnyOf schema) :or]
55-
57+
5658
(< 0 (count (.getAllOf schema)))
5759
[(.getAllOf schema) :and]
58-
59-
:else
60+
61+
:else ;; TODO: Implement oneOf
6062
(throw (IllegalArgumentException. "Unsupported composite schema. Use either anyOf, allOf")))]
6163
(->> schemas
6264
(map p/transform)
@@ -101,7 +103,6 @@
101103
BooleanSchema
102104
(p/transform [_] boolean?)
103105

104-
;; TODO: Implement oneOf
105106
ComposedSchema
106107
(p/transform [schema]
107108
(transform-composed schema))
@@ -116,16 +117,16 @@
116117

117118
JsonSchema
118119
(p/transform [schema]
119-
(let [pred (fn [type]
120-
(case type
120+
(let [pred (fn [typ]
121+
(case typ
121122
"array" (transform-array schema)
122123
"boolean" boolean?
123124
"integer" int?
124125
"null" nil?
125126
"number" number?
126127
"object" (transform-object schema)
127128
"string" string?
128-
(throw (Exception. (str "Unsupported schema" schema)))))
129+
(throw (IllegalArgumentException. (format "Unsupported type %s for schema %s" typ schema)))))
129130
types (.getTypes schema)]
130131
(case (count types)
131132
0 (transform-composed schema)
@@ -182,3 +183,6 @@
182183
body-spec
183184
[:or nil? body-spec])})
184185
{})))
186+
187+
(comment
188+
(set! *warn-on-reflection* true))

test/navi/transform_test.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@
175175
(.setAnyOf [(StringSchema.) (IntegerSchema.)])))))
176176
(is (= [:or string? int?]
177177
(p/transform (doto (JsonSchema.)
178-
(.setAnyOf [(.types (JsonSchema.) #{"string"}) (.types (JsonSchema.) #{"integer"})]))))))
178+
(.setAnyOf [(.types (JsonSchema.) #{"string"})
179+
(.types (JsonSchema.) #{"integer"})]))))))
179180
(testing "allOf"
180181
(is (= [:and string? int?]
181182
(p/transform (doto (ComposedSchema.)
182183
(.setAllOf [(StringSchema.) (IntegerSchema.)])))))
183184
(is (= [:and string? int?]
184185
(p/transform (doto (JsonSchema.)
185-
(.setAllOf [(.types (JsonSchema.) #{"string"}) (.types (JsonSchema.) #{"integer"})])))))))
186+
(.setAllOf [(.types (JsonSchema.) #{"string"})
187+
(.types (JsonSchema.) #{"integer"})])))))))

0 commit comments

Comments
 (0)