Skip to content

Commit 85473db

Browse files
committed
[schema] support cookie params, tests
1 parent e6c9e64 commit 85473db

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/navi/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(.setResolveFully true))
2121
contents (.readContents (OpenAPIV3Parser.) api-spec nil parse-options)
2222
paths (.getPaths (.getOpenAPI contents))]
23-
(mapv identity (i/update-kvs paths identity #(i/path-item->data % handlers)))))
23+
(i/update-kvs paths identity #(i/path-item->data % handlers))))
2424

2525
(comment
2626
(require '[clojure.pprint :as pp])

src/navi/transform.clj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StringSchema
2525
UUIDSchema]
2626
[io.swagger.v3.oas.models.parameters
27+
CookieParameter
2728
HeaderParameter
2829
PathParameter
2930
QueryParameter
@@ -117,6 +118,9 @@
117118
ByteArraySchema
118119
(p/transform [_] any?)
119120

121+
nil
122+
(p/transform [_] any?)
123+
120124
Schema
121125
(p/transform [schema]
122126
(if-let [t (first (.getTypes schema))]
@@ -125,9 +129,6 @@
125129
(throw (Exception. (str "Unsupported schema" schema))))
126130
(throw (Exception. "Missing schema"))))
127131

128-
nil
129-
(p/transform [_] any?)
130-
131132
;; TODO: Better. The extra [] is there to help with merge-with into
132133
PathParameter
133134
(p/transform [param]
@@ -141,6 +142,10 @@
141142
(p/transform [param]
142143
{:query [(i/->param-schema param)]})
143144

145+
CookieParameter
146+
(p/transform [param]
147+
{:cookie [(i/->param-schema param)]})
148+
144149
;; TODO: Handle more kinds of request-bodies
145150
RequestBody
146151
(p/transform [param]

test/navi/transform_test.clj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
(:import
1414
[io.swagger.v3.oas.models.media
1515
ArraySchema
16+
BinarySchema
17+
ByteArraySchema
1618
ComposedSchema
1719
Content
1820
IntegerSchema
@@ -24,6 +26,7 @@
2426
StringSchema
2527
UUIDSchema]
2628
[io.swagger.v3.oas.models.parameters
29+
CookieParameter
2730
HeaderParameter
2831
PathParameter
2932
QueryParameter
@@ -70,7 +73,13 @@
7073
(is (= [:sequential string?]
7174
(p/transform arr)))
7275
(is (= [:sequential string?]
73-
(p/transform arr-json))))))
76+
(p/transform arr-json)))))
77+
(testing "byte array"
78+
(is (= any? (p/transform (ByteArraySchema.)))))
79+
(testing "binary"
80+
(is (= any? (p/transform (BinarySchema.)))))
81+
(testing "nil"
82+
(is (= any? (p/transform nil)))))
7483

7584
(deftest string-formats
7685
(testing "uuid"
@@ -119,6 +128,13 @@
119128
(.setSchema (IntegerSchema.)))]
120129
(is (= {:header [[:x int?]]}
121130
(p/transform param)))))
131+
(testing "cookie"
132+
(let [param (doto (CookieParameter.)
133+
(.setName "x")
134+
(.setRequired true)
135+
(.setSchema (IntegerSchema.)))]
136+
(is (= {:cookie [[:x int?]]}
137+
(p/transform param)))))
122138
(testing "required request body"
123139
(let [media (doto (MediaType.)
124140
(.setSchema (ObjectSchema.)))

0 commit comments

Comments
 (0)